按两点之间的距离设置区域

时间:2012-02-09 00:54:42

标签: ios geolocation mkmapview

我有MKMapView中心的第一个点和以米为单位的距离来映射中心应该是的左边界。

如何为此设置区域?

1 个答案:

答案 0 :(得分:1)

给定中心坐标和从中心到边界的距离(以米为单位),您可以使用MKCoordinateRegionMakeWithDistance功能创建区域:

CLLocationCoordinate2D centerCoord = CLLocationCoordinate2DMake(lat, lng);

CLLocationDistance centerToBorderMeters = 5000;

MKCoordinateRegion rgn = MKCoordinateRegionMakeWithDistance 
                           (centerCoord, 
                            centerToBorderMeters * 2,   //vertical span
                            centerToBorderMeters * 2);  //horizontal span

[mapView setRegion:rgn animated:YES];