-6

如何从以下代码中提取经纬度:

CLGeocoder *geocoder = [CLGeocoder new];
[geocoder geocodeAddressString:city completionHandler:^(NSArray *placemarks, NSError *error) {
if (error) {
    NSLog(@"Error: %@", [error localizedDescription]);
}

if ([placemarks count] > 0) {

    CLPlacemark *placemark = [placemarks lastObject]; 
    NSLog(@"Location is: %@", placemark.location);

}

从 nslog 输出我得到:

Location is: <+45.46368100,+9.18817140> +/- 100.00m (speed -1.00 mps / course -1.00) @ 25/09/2013 11:04:20 British Summer Time

我只想获取纬度和经度并将它们存储到变量中。

4

1 回答 1

1
CLLocationCoordinate2D coordinate = placemark.location.coordinate

然后:

coordinate.longitude
coordinate.latitude

文档:https ://developer.apple.com/library/ios/documentation/CoreLocation/Reference/CLPlacemark_class/Reference/Reference.html

于 2013-09-25T10:20:41.107 回答