gpt4 book ai didi

iphone - 通过 CLGeocoder 的方法查找一个区域中的所有位置

转载 作者:行者123 更新时间:2023-11-28 22:56:33 25 4
gpt4 key购买 nike

使用“–reverseGeocodeLocation:completionHandler:”方法对位置进行反向地理编码很方便。但是如何获取一个区域内的所有位置。

附言。如果一个地区有几个地方。我怎样才能使用区域信息找出所有的地方?比如反向地理编码一个位置,给定一个坐标,返回一个位置。这里我想给出一个区域,返回该区域中的所有位置。

最佳答案

有一个返回 JSON 的 google Geocoder API,它只是一种使用 GET 方法的网络服务

This是 Google Gecoder API 和 This是该 Web 服务的链接,在此链接中我将区域名称指定为伦敦。

注意:您需要在代码中包含 SBJson 库。

在该链接的末尾,我附加了地址,如果您附加地址 - 您需要提供区域名称(或者)如果您附加纬度和经度,您需要提供坐标,它会相应地返回结果。

调用google api的代码会是这样的

                //Call the Google API
NSString *req = [NSString stringWithFormat:@"http://maps.google.com/maps/api/geocode/json?sensor=false&address=%@", esc_addr];
NSLog(@"The get address is %@", req);
//Pass the string to the NSURL
NSString *result = [NSString stringWithContentsOfURL:[NSURL URLWithString:req] encoding:NSUTF8StringEncoding error:NULL];
NSLog(@"The result is %@", result);
//Initialize the SBJSON Class
SBJSON *parser = [[SBJSON alloc] init];
NSError *error = nil;
//Get the resullts and stored in the address array
addressArray = [parser objectWithString:result error:&error];
//Get the latitude values for the given address
NSDictionary *dict = [[[addressArray valueForKey:@"results"] valueForKey:@"geometry"] valueForKey:@"location"];
self.latitudeValue = [[dict valueForKey:@"lat"] objectAtIndex:0];
self.longitudeValue = [[dict valueForKey:@"lng"] objectAtIndex:0];
NSLog(@"LAT : %@",self.latitudeValue);
NSLog(@"LONG : %@",self.longitudeValue);

关于iphone - 通过 CLGeocoder 的方法查找一个区域中的所有位置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10673912/

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