在iPhone应用程序中,如何计算MKMapView
中两点之间的距离,如下图所示?如何计算MkMapview中两点之间的距离?
第一个点将是mapview中可视地图的中心点。
第二个点将是mapview的可见矩形的任何角落(这里,例如,我已采取左上角的点)。
我要计算这个米的距离。我怎样才能做到这一点?
我的目标是计算MKMapview
中可见的Map矩形的比率。
在iPhone应用程序中,如何计算MKMapView
中两点之间的距离,如下图所示?如何计算MkMapview中两点之间的距离?
第一个点将是mapview中可视地图的中心点。
第二个点将是mapview的可见矩形的任何角落(这里,例如,我已采取左上角的点)。
我要计算这个米的距离。我怎样才能做到这一点?
我的目标是计算MKMapview
中可见的Map矩形的比率。
你可以得到纬度与中心/ LON:
convertPoint:toCoordinateFromView:
LOC1和LOC2都是CLLocation OBJ文件。
CLLocationDistance dist = [loc1 distanceFromLocation:loc2];
所以这两个小技巧可以帮助你。如果你需要一些代码,让我知道:-)
这里是你如何计算想要的距离:
// You first have to get the corner point and convert it to a coordinate
MKMapRect mapRect = self.mapView.visibleMapRect;
MKMapPoint cornerPointNW = MKMapPointMake(mapRect.origin.x, mapRect.origin.y);
CLLocationCoordinate2D cornerCoordinate = MKCoordinateForMapPoint(cornerPointNW);
// Then get the center coordinate of the mapView (just a shortcut for convenience)
CLLocationCoordinate2D centerCoordinate = self.mapView.centerCoordinate
// And then calculate the distance
CLLocationDistance distance = [cornerCoordinate distanceFromLocation:centerCoordinate];
centerCoordinate和cornerCoordinate需要为distanceFromLocation类型的CLLocation类型工作 – Daniel
斯威夫特3+
let distance: CLLocationDistance = location1.distance(from: location2)
谢谢答复你可以告诉我如何获得经纬度或角点坐标(第二点)我可以得到中心点的坐标(第一点) – ios
[This answer](http://stackoverflow.com/questions/2081753/getting-the- bounds-of-an-mkmapview/2082247#2082247)讲述了如何获得角点的纬度/经度TS。 – progrmr
当我与谷歌交叉检查。使用mapKit查找距离不正确。 –