我正在尝试通过提供地址字符串来查找经度和纬度。我得到两个值的0.000和0.000。

我正在使用MapKit,iOS 7,XCode 5

CLGeocoder *geocoder = [[CLGeocoder alloc] init];
[geocoder geocodeAddressString:@"Fairfax, VA" completionHandler:^(NSArray* placemarks, NSError* error){
    for (CLPlacemark* aPlacemark in placemarks)
    {
        CLLocationCoordinate2D coordinate;

        coordinate.longitude = aPlacemark.location.coordinate.longitude;
        coordinate.latitude = aPlacemark.location.coordinate.latitude;

        // updatedCoordinates is a property in my class and I am setting it's value
        // here and using it in bunch of other places.
        self.updatedCoordinates = coordinate;
    }
}];

最佳答案

-(void)getPlacemarkInfo:(NSString*)placeName {
    // place name can be paris, etc
    CLGeocoder *geocoder = [[CLGeocoder alloc] init];
    [geocoder geocodeAddressString:placeName completionHandler:^(NSArray *placemarks, NSError *error) {
        if (error) {
            NSLog(@"%@", error);
        } else {
            CLPlacemark *placemark = [placemarks lastObject];
     //     placemark.location.coordinate.latitude; will returns latitude
     //     placemark.location.coordinate.longitude; will returns longitude
        }
    }];
}

关于iphone - 使用CLGeocoder查找经度和纬度,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/18767351/

10-11 11:01