我打算假設您正在查找地址並在您的應用中顯示該地址。您可以使用Geocoder API進行帶邊界(或不帶邊界)的查找。我正在使用這個NSString格式:NSString *geocoderURLFormat = @"http://maps.googleapis.com/maps/api/geocode/json?address=%@&bounds=%@&sensor=true"
。
此調用的回調將返回該位置的建議視口 - 西南和東北經緯度值。使用這些,你可以設置MKMapView
對象的區域是這樣的:
CLLocationCoordinate2D coord;
coord.latitude = location.latitude;
coord.longitude = location.longitude;
MKCoordinateSpan span;
span.latitudeDelta = location.swLatitude > location.neLatitude ? location.swLatitude - location.neLatitude : location.neLatitude - location.swLatitude;
span.longitudeDelta = location.swLongitude > location.neLongitude ? location.swLongitude - location.neLongitude : location.neLongitude - location.swLongitude;
MKCoordinateRegion region;
region.span = span;
region.center = coord;
[mapView setRegion:region animated:YES];
請注意,我仍然對MKCoordinateSpan
的latitudeDelta
和longitudeDelta
值有點模糊,代碼因此,醜陋。我使用的location
變量是從調用Geocoder的結果中構建的。
希望這會有所幫助!