gpt4 book ai didi

objective-c - objective c 如何获取给定坐标的地标

转载 作者:可可西里 更新时间:2023-11-01 04:48:29 26 4
gpt4 key购买 nike

我有一个与反向地理编码相关的问题。

在我的应用程序中,我有一些坐标(不是我当前的坐标),我想将它们转换为地标。我已经挖掘了很多网站和代码,但它们都是关于当前位置的反向地理编码......

有没有办法获取指定坐标(不是当前位置)的地标?

如果有,请帮我提供一些代码或引用。

最佳答案

您可以通过两种方式实现:-

第一种方式:-使用 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的两个委托(delegate)方法

- (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);

}

关于objective-c - objective c 如何获取给定坐标的地标,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9031373/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com