如果我给这个方法的任何地址,它根本不是在调用。但是如果给“1800 Ellis St,San Francisco,CA 94102,United States”它正在被调用。告诉我有什么问题。
[geocoder geocodeAddressString:@"#83 2nd Floor Diagonal Road V.V.Puram Bangalore 560004 India"
completionHandler:^(NSArray* placemarks1, NSError* error){
for (CLPlacemark* aPlacemark in placemarks1)
{
annotationCoord= aPlacemark.location.coordinate;
[locationManager stopUpdatingLocation];
MKCoordinateRegion region;
region.center.latitude=annotationCoord.latitude;
region.center.longitude=annotationCoord.longitude;
region.span.longitudeDelta=0.;
region.span.latitudeDelta=0.;
self.mapView.showsUserLocation = YES;
[self.mapView setRegion:region];
_annotation=[[LDAnnotation alloc]initWithCoordinate:annotationCoord andTitle:@""subTitle:@""];
[self.mapView addAnnotation:(id<MKAnnotation>)_annotation];
[_searchAddressTF resignFirstResponder];
}
}];
答案 0 :(得分:0)
你的placemarks1数组可能是空的,因为你没有检查它是否存在,该块只是没有执行。这是常用格式
[self.geocoder geocodeAddressString:address completionHandler:^(NSArray *placemarks, NSError *error) {
if ([placemarks count] > 0) {
CLPlacemark *placemark = [placemarks objectAtIndex:0];
CLLocation *location = placemark.location;
CLLocationCoordinate2D coordinate = location.coordinate;
您可以尝试打印地点标记的大小。如果您还没有看过,请查看此页面。 http://code.tutsplus.com/tutorials/forward-geocoding-with-clgeocoder--mobile-11011