【发布时间】:2012-02-06 18:07:12
【问题描述】:
我希望能够通过允许用户在 UIAlertView 中输入地址或位置来更新 MKMapView 上显示的区域。我目前有:
if (geocoder.geocoding)
[geocoder cancelGeocode];
[geocoder geocodeAddressString:[[alertView textFieldAtIndex:0] text] completionHandler:^(NSArray *placemarks, NSError *error) {
if (!error) {
NSLog(@"Found a location");
} else {
NSLog(@"Error in geocoding");
}
NSLog(@"Num found: %d", [placemarks count]);
CLPlacemark *placemark = [placemarks objectAtIndex:0];
MKCoordinateRegion region;
region.center.latitude = placemark.region.center.latitude;
region.center.longitude = placemark.region.center.longitude;
MKCoordinateSpan span;
double radius = placemark.region.radius / 1000;
NSLog(@"Radius is %f", radius);
span.latitudeDelta = radius / 112.0;
//span.longitudeDelta = ???
region.span = span;
NSLog(@"Region is %f %f %f", region.center.latitude, region.center.longitude, span.latitudeDelta);
[mapView setRegion:region animated:YES];
}];
我的问题是我不确定如何计算经度增量。
【问题讨论】:
-
您可以将其设置为等于 latitudeDelta,地图视图将根据需要进行调整。但是您不需要首先自己计算跨度。您可以使用
region = MKCoordinateRegionMakeWithDistance(placemark.region.center, placemark.region.radius, placemark.region.radius);。不确定您问题的第二部分。 -
这似乎有效。我假设我必须使用第 3 方地理编码器才能查看所有具有相同名称的结果。
-
安娜你能把这个添加为答案吗?
标签: ios mkmapview cllocation mkcoordinateregion clgeocoder