Question

It is convenient to use "– reverseGeocodeLocation:completionHandler:" method to Reverse Geocoding a Location. But how to obtain all locations in a region.

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.

Was it helpful?

Solution

There is a google Geocoder API which returns JSON , It is just a kind of a web service which uses GET method

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.

Note: You need to include SBJson library to your code.

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

                //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);
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top