我有一个简单的问题。
MKReverseCoder已被弃用,自iOS 5以来不再可用。我们必须使用CLGeocoder。但是,有很多人仍在使用iOS4。新的应用程序如何在iOS4和iOS5上进行地理编码?
谢谢!
MKReverseCoder已被弃用,自iOS 5以来不再可用。我们必须使用CLGeocoder。但是,有很多人仍在使用iOS4。新的应用程序如何在iOS4和iOS5上进行地理编码?
谢谢!
viewDidLoad()
中,然后创建一些标签或文本区域来显示数据。您可以参考这个链接:http://jonathanfield.me/jons-blog/clgeocoder-example.html。请注意不要更改HTML标记。[super viewDidLoad]; locationManager.delegate = self; [locationManager startUpdatingLocation];
locationManager.desiredAccuracy = kCLLocationAccuracyBestForNavigation;
[self.CLGeocoder reverseGeocodeLocation: locationManager.location completionHandler:
^(NSArray *placemarks, NSError *error) {
CLPlacemark *placemark = [placemarks objectAtIndex:0];
isoCountryCode.text = placemark.ISOcountryCode;
country.text = placemark.country;
postalCode.text= placemark.postalCode;
adminArea.text=placemark.administrativeArea;
subAdminArea.text=placemark.subAdministrativeArea;
locality.text=placemark.locality;
subLocality.text=placemark.subLocality;
thoroughfare.text=placemark.thoroughfare;
subThoroughfare.text=placemark.subThoroughfare;
//region.text=placemark.region;
}];
MKReverseGeocoder
仍可在iOS5上使用,只是已弃用,这意味着它将在稍后的某个时间被移除(比如在类似iOS6的发布时)。因此,您现在可以继续使用它而不会遇到任何问题。
- (IBAction)geoCodeLocation:(id)sender{
[self.geoCoder reverseGeocodeLocation: locationManager.location completionHandler:
^(NSArray *placemarks, NSError *error) {
CLPlacemark *placemark = [placemarks objectAtIndex:0];
NSLog(@"placemark %@",placemark);
//String to hold address
NSString *locatedAt = [[placemark.addressDictionary valueForKey:@"FormattedAddressLines"] componentsJoinedByString:@", "];
NSLog(@"addressDictionary %@", placemark.addressDictionary);
NSLog(@"placemark %@",placemark.region);
NSLog(@"placemark %@",placemark.country); // Give Country Name
NSLog(@"placemark %@",placemark.locality); // Extract the city name
NSLog(@"location %@",placemark.name);
NSLog(@"location %@",placemark.ocean);
NSLog(@"location %@",placemark.postalCode);
NSLog(@"location %@",placemark.subLocality);
NSLog(@"location %@",placemark.location);
//Print the location to console
NSLog(@"I am currently at %@",locatedAt);
//Set the label text to current location
[locationLabel setText:locatedAt];
}];
更多信息请参见CLPlacemark的属性。