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

标签 iphone ios location clgeocoder

使用“–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/

相关文章:

iOS8 Touch ID 获取错误 : Pending UI mechanism already set

iphone - CATiledLayer 在绘制内容之前消隐图 block

ios - Offcanvas 菜单 - CSS 过渡不适用于 iphone 3 和 4

iphone - 如何在 xcode 之外修改 .xib 文件?

javascript - Window.location.href post参数到actionresult asp.net mvc

ios - 如何在 Objective C 中从键盘的数字侧开始

iOS - 生成并播放不确定的简单音频(正弦波)

ios - 如何处理高度依赖当前位置的应用程序中的位置拒绝?

python - 根据 WiFi 确定笔记本电脑的位置

ios - UIImageView 边界、框架