地理编码方法看起来正确,但我总是得到0 0作为我的坐标

时间:2014-06-30 17:34:55

标签: ios ios7 mapkit geocoding

这不应该这么难......我只是试图对地址字符串进行地理编码,以便我可以在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

0 个答案:

没有答案