概述
通过经纬度获取地址信息
- (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的全部内容,希望文章能够帮你解决7.8 Converting Longitude and Latitude to a Meaningful Address所遇到的程序开发问题。
如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。
发表评论 取消回复