这不应该这么难......我只是试图对地址字符串进行地理编码,以便我可以在viewDidLoad
上的地图上缩放到该地址,但每次运行地理编码方法时我都会得到0 0作为我的lat和long。
CLGeocoder *geocoder = [[CLGeocoder alloc] init];
[geocoder geocodeAddressString:addressOfSelected completionHandler:^(NSArray *placemarks, NSError *error) {
if (error) {
NSLog(@"Geocode failed with error: %@", error);
return;
}
if (placemarks && placemarks.count > 0)
{
CLPlacemark *placemark = placemarks[0];
CLLocation *location = placemark.location;
self.shackCoords = CLLocationCoordinate2DMake(location.coordinate.latitude, location.coordinate.longitude);
}
}];
MKCoordinateRegion region;
region.center.latitude = self.shackCoords.latitude;
region.center.longitude = self.shackCoords.longitude;
region.span.latitudeDelta = .05;
region.span.longitudeDelta = .05;
[self.mapView setRegion:region];
shackCoords
只是CLLocationCoordinate2D
。