我有一个与反向地理编码有关的问题。
在我的应用程序中,我有一些坐标(不是我当前的坐标),我想将它们转换为地标。我挖了很多网站和代码,但它们都是关于当前位置的反向地理编码......
有没有办法获得指定坐标的地标(不是当前位置)?
如果有,请帮我提供一些代码或参考资料。
答案 0 :(得分:2)
您可以通过两种方式实现这一目标: -
第一种方式: - 使用google 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);
}