简体   繁体   English

通过CLGeocoder的方法查找区域中的所有位置

[英]Find all locations in a region through methods of CLGeocoder

It is convenient to use "– reverseGeocodeLocation:completionHandler:" method to Reverse Geocoding a Location. 使用“ - reverseGeocodeLocation:completionHandler:”方法来反向对位置进行地理编码很方便。 But how to obtain all locations in a region. 但是如何获得一个地区的所有地点。

ps. PS。 If there are several places in a region. 如果一个地区有几个地方。 How could I use the region information to find out all the places? 我如何使用区域信息找出所有地方? Such as reverse geocoding a location, given a coordinate, return a location. 如反向地理编码一个位置,给定一个坐标,返回一个位置。 Here I wanna give a region, return all locations in the region. 在这里,我想给一个地区,返回该地区的所有位置。

There is a google Geocoder API which returns JSON , It is just a kind of a web service which uses GET method 有一个谷歌Geocoder API返回JSON,它只是一种使用GET方法的Web服务

And This is the Google Gecoder API and This is the link for that web service and in this link i have given the region name as london. 是Google Gecoder API, 是该Web服务的链接,在此链接中,我将区域名称命名为london。

Note: You need to include SBJson library to your code. 注意:您需要在代码中包含SBJson库。

At the end of that link i have appended address, if you append address- you need to give the region name (or) if you append latitude and longitude, you need to give coordinates and it will return the results accordingly. 在该链接的末尾,我有附加地址,如果你附加地址 - 你需要给出区域名称(或)如果你追加纬度和经度,你需要给出坐标,它将相应地返回结果。

And the code for calling google api will be like this 调用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);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM