iPhone开发 - 在地图上显示两个位置

Bri*_*ian 2 iphone google-maps mkcoordinateregion mkcoordinatespan

现在我有两个位置的坐标,比如说位置A,纬度40和经度-80,位置B,纬度30和经度-70,

我想创建一个mapView,我可以看到两个位置都有适当的观看距离.

我通过找到中点得到了新的坐标(在这个例子中,{35,-75}),但问题是,

如何获得适当的观看距离?特别是,我如何计算CLLocationDistance(如果我使用的是MKCoordinateRegionMakeWithDistance)或MKCoordinateSpan(如果我使用的是MKCoordinateSpanMake).

提前致谢.

And*_*sky 11

这就是我的想法:

CLLocation *pointALocation = [[CLLocation alloc] initWithLatitude:middlePoint.latitude longitude:middlePoint.longitude];
CLLocation *pointBLocation = [[CLLocation alloc] initWithLatitude:pointB.latitude longitude:pointB.longitude];
CLLocationDistance d = [pointALocation distanceFromLocation:pointBLocation];
MKCoordinateRegion r = MKCoordinateRegionMakeWithDistance(middlePoint, 2*d, 2*d);
[mapView setRegion:r animated:YES];
Run Code Online (Sandbox Code Playgroud)

CLLocationDistance d包含要查看的中心和第二个点之间的距离(以米为单位).然后,您可以使用中间点和两米的距离来设置您想要在屏幕上显示的区域.通过使用2*d,我确保屏幕有足够的空间来显示第二个点.

希望能帮助到你.

- ank

  • 这段时间不知道地图套件功能让我感到愚蠢.它只是表明即使在将近三年后,答案也可能是相关的.谢谢! (3认同)