目标c如何获得给定坐标的地标
我有一个有关反向地理编码的问题。
在我的应用程序中,我有一些坐标(不是我当前的坐标),我想将它们转换为地标。 我挖了很多网站和代码,但他们都是关于当前位置的反向地理编码…
有没有办法获得指定坐标(不是当前位置)的地标?
如果有,请帮我一些代码或参考。
你可以通过两种方式实现这一点:
第一种方法: – 使用谷歌API获取信息
-(void)findAddresstoCorrespondinglocation { NSString *str = [NSString stringWithFormat:@"http://maps.googleapis.com/maps/api/geocode/json?latlng=%f,%f&sensor=false",myCoordInfo.latitude,myCoordInfo.longitude]; NSURL *url = [NSURL URLWithString:[str stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]]; ASIHTTPRequest *request = [[[ASIHTTPRequest alloc] initWithURL:url] autorelease]; [request setRequestMethod:@"GET"]; [request setDelegate:self]; [request setDidFinishSelector: @selector(mapAddressResponse:)]; [request setDidFailSelector: @selector(mapAddressResponseFailed:)]; [networkQueue addOperation: request]; [networkQueue go]; }
作为响应,您将获得有关您指定的位置坐标的所有信息。
第二种方法: –
实施反向地理编码
a。)添加mapkit
框架
b。)在.h文件中MKReverseGeocoder
实例
MKReverseGeocoder *reverseGeocoder;
c。)在.m文件中
self.reverseGeocoder = [[MKReverseGeocoder alloc] initWithCoordinate:cordInfo]; reverseGeocoder.delegate = self; [reverseGeocoder start];
实现MKReverseGeoCoder
两个委托方法
- (void)reverseGeocoder:(MKReverseGeocoder *)geocoder didFailWithError:(NSError *)error { NSLog(@"MKReverseGeocoder has failed."); } - (void)reverseGeocoder:(MKReverseGeocoder *)geocoder didFindPlacemark:(MKPlacemark *)placemark { MKPlacemark * myPlacemark = placemark; NSString *city = myPlacemark.thoroughfare; NSString *subThrough=myPlacemark.subThoroughfare; NSString *locality=myPlacemark.locality; NSString *subLocality=myPlacemark.subLocality; NSString *adminisArea=myPlacemark.administrativeArea; NSString *subAdminArea=myPlacemark.subAdministrativeArea; NSString *postalCode=myPlacemark.postalCode; NSString *country=myPlacemark.country; NSString *countryCode=myPlacemark.countryCode; NSLog(@"city%@",city); NSLog(@"subThrough%@",subThrough); NSLog(@"locality%@",locality); NSLog(@"subLocality%@",subLocality); NSLog(@"adminisArea%@",adminisArea); NSLog(@"subAdminArea%@",subAdminArea); NSLog(@"postalCode%@",postalCode); NSLog(@"country%@",country); NSLog(@"countryCode%@",countryCode); }