开发者

iPhone reverse geocoding: give all possible streets/suburbs?

I know Core Location isnt always accurate on the iPhone. Is there a way to use the location (lat/long) along with the accuracy to then grab all of the possible suburbs/streets in that area?

So 开发者_运维知识库instead of using the reverse geocoding and having it guess the 'best possible suburb/street, is there a way to make it give an array (or in some other format) of all the possible suburbs/streets that it could consider?

Thanks!!


So, the best approach to do this, is using the Google maps API. For example, take a look ate the following url: http://maps.google.com/maps/geo?q=38.4417077,-90.7122047&output=xml

As you can see, for this pair (latitude, longitude) you have 10 possible placemarks for this coordinates.

The documentation for this you can find at: http://code.google.com/apis/maps/documentation/geocoding/index.html

You can see that you get the info in XML, JSON, CSV.

Take a look at the status code, it is important to verify if the request was successful (usually 200 or 200 and something).

So, how to use it VFN?

It is simple.



double latitude = coordinate.latitude;
    double longitude = coordinate.longitude;

    NSString *urlString = [NSString stringWithFormat:@"http://maps.google.com/maps/geo?q=%f,%f&output=xml", latitude, longitude];   
    NSURL *url = [NSURL URLWithString:urlString];


    NSString *locationString = [NSString stringWithContentsOfURL:url encoding:NSUTF8StringEncoding error:nil];

on locationString is the response from Google Geocoder, now you can use the info as you want. Remember to first check the status code, and than parse the info. If you want only the first placemark that is selected by Google Geocoder, I would suggest you to use the output in CSV, that is easy to work with.

If you have any queries, let me know!

Cheers,
VFN

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜