从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;
}
网友评论