如何从以下代码中提取lat和long:
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
我想得到lat和lon并将它们存储到变量中。
答案 0 :(得分:1)
CLLocationCoordinate2D coordinate = placemark.location.coordinate
然后:
coordinate.longitude
coordinate.latitude