美文网首页
MKMapView 的一些自定义tool

MKMapView 的一些自定义tool

作者: 七维树 | 来源:发表于2018-03-20 14:05 被阅读31次

从MapView的两个ViewPoint的点,获取两点之间的距离(米)

- (double)getMetersBetweenViewPointA:(CGPoint)pointA pointB:(CGPoint)pointB fromMapView:(MKMapView *)mapView {
    MKMapPoint mA = [self convertViewPoint:pointA toMapPointFromMapView:mapView];
    MKMapPoint mB = [self convertViewPoint:pointB toMapPointFromMapView:mapView];
    double meters = MKMetersBetweenMapPoints(mA,mB);
    return meters;
}

转化MapView上的View的点转化为MKMapPoint

- (MKMapPoint)convertViewPoint:(CGPoint)viewPoint toMapPointFromMapView:(MKMapView *)mapView {
    CLLocationCoordinate2D coord2D = [mapView convertPoint:viewPoint toCoordinateFromView:mapView];
    MKMapPoint mapPoint = MKMapPointForCoordinate(coord2D);
    return mapPoint;
}

相关文章

网友评论

      本文标题:MKMapView 的一些自定义tool

      本文链接:https://www.haomeiwen.com/subject/uvxbqftx.html