本文主要是介绍7.8 Converting Longitude and Latitude to a Meaningful Address,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
通过经纬度获取地址信息
- (void)viewDidLoad
{
[superviewDidLoad];
CLLocation *location = [[CLLocationalloc] initWithLatitude:39.904989
longitude:116.405285];
self.myGeocoder = [[CLGeocoderalloc] init];
[self.myGeocoder
reverseGeocodeLocation:location completionHandler:^(NSArray *placemarks,NSError *error) {
if (error == nil && [placemarkscount] > 0){
CLPlacemark *placemark = [placemarks objectAtIndex:0]; /* We received the results */
NSLog(@"Country = %@", placemark.country);
NSLog(@"name = %@", placemark.name);
NSLog(@"thoroughfare = %@", placemark.thoroughfare);
NSLog(@"subThoroughfare = %@", placemark.subThoroughfare);
NSLog(@"locality = %@", placemark.locality);
NSLog(@"subLocality = %@", placemark.subLocality);
NSLog(@"administrativeArea = %@", placemark.administrativeArea);
NSLog(@"subAdministrativeArea = %@", placemark.subAdministrativeArea);
NSLog(@"postalCode = %@", placemark.postalCode);
NSLog(@"ISOcountryCode = %@", placemark.ISOcountryCode);
NSLog(@"inlandWater = %@", placemark.inlandWater);
NSLog(@"ocean = %@", placemark.ocean);
NSLog(@"areasOfInterest = %@", placemark.areasOfInterest);
}
else if (error ==nil &&
[placemarkscount] == 0){
NSLog(@"No results were returned.");
}
else if (error !=nil){
NSLog(@"An error occurred = %@", error); }
}];
}
输出:
2014-04-08 14:12:59.756 cookbook[592:c07] Country = China
2014-04-08 14:12:59.758 cookbook[592:c07] name = Danta Coffee
2014-04-08 14:12:59.758 cookbook[592:c07] thoroughfare = Danta Coffee
2014-04-08 14:12:59.758 cookbook[592:c07] subThoroughfare = (null)
2014-04-08 14:12:59.759 cookbook[592:c07] locality = (null)
2014-04-08 14:12:59.759 cookbook[592:c07] subLocality = Dongcheng
2014-04-08 14:12:59.760 cookbook[592:c07] administrativeArea = Beijing
2014-04-08 14:12:59.760 cookbook[592:c07] subAdministrativeArea = (null)
2014-04-08 14:12:59.760 cookbook[592:c07] postalCode = (null)
2014-04-08 14:12:59.760 cookbook[592:c07] ISOcountryCode = CN
2014-04-08 14:12:59.761 cookbook[592:c07] inlandWater = (null)
2014-04-08 14:12:59.761 cookbook[592:c07] ocean = (null)
2014-04-08 14:12:59.761 cookbook[592:c07] areasOfInterest = (null)
如果输入的经纬度是:
CLLocation *location = [[CLLocation alloc] initWithLatitude:24.5
longitude:118.13];
则输出是:
2014-04-08 14:16:19.442 cookbook[613:c07] Country = China
2014-04-08 14:16:19.443 cookbook[613:c07] name = No. 1389 Xianyue Road
2014-04-08 14:16:19.443 cookbook[613:c07] thoroughfare = Xianyue Road
2014-04-08 14:16:19.444 cookbook[613:c07] subThoroughfare = No. 1389
2014-04-08 14:16:19.444 cookbook[613:c07] locality = Xiamen
2014-04-08 14:16:19.444 cookbook[613:c07] subLocality = Huli
2014-04-08 14:16:19.444 cookbook[613:c07] administrativeArea = Fujian
2014-04-08 14:16:19.445 cookbook[613:c07] subAdministrativeArea = (null)
2014-04-08 14:16:19.445 cookbook[613:c07] postalCode = (null)
2014-04-08 14:16:19.445 cookbook[613:c07] ISOcountryCode = CN
2014-04-08 14:16:19.445 cookbook[613:c07] inlandWater = (null)
2014-04-08 14:16:19.446 cookbook[613:c07] ocean = (null)
2014-04-08 14:16:19.446 cookbook[613:c07] areasOfInterest = (null)
这篇关于7.8 Converting Longitude and Latitude to a Meaningful Address的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!