Get Coordinates for given Location

懵懂的女人 提交于 2020-01-13 07:06:27

问题


OK, here's what I want to implement and I need your ideas :

  • Input a geo location by name/address/etc (e.g. London, Oxford Street 20)
  • Get the point's longitude/latitude

My Questions :

  • How would you go about that?
  • Is using Google Maps API (that's what I first thought of) my only solution?

It'd be better if the service used CAN be freely integrated in a commercial app - so any idea is welcome... :-)


回答1:


There is a built in API for that.
For iOS 5 and newer you can use CLGeocoder and for older version you will need to use some extern libraries.

Just call

- (void)geocodeAddressString:(NSString *)addressString completionHandler:(CLGeocodeCompletionHandler)completionHandler

where you want to get the location. It runs async and in the completionHandler you will get an array of all possible placemarks for your address where the first one is the most accurate. As apple says:

For most geocoding requests, this array should contain only one entry. However, forward-geocoding requests may return multiple placemark objects in situations where the specified address could not be resolved to a single location.

Off topic:
Am I the only one whos first thoughts about Oxford was "What does he mean with this weird Hex value?"




回答2:


What you are trying to do is basically geocoding. Major map providers like Google, Bing and Yahoo (and many more) all offer some form of Geocoding API for you to take advantage of. Check out the following quick links:

  • Google Maps Geocoding API
  • Bing Locations API
  • Yahoo! Maps Web Services (Geocoding API)

Edit: (just saw the objective-c tag)

Note that these are non-native solutions. However, the provided APIs are typically REST-based (with output as xml/json), it shouldn't be hard for you to consume these services to grab the gecoded lat-long that you want from within your app.



来源:https://stackoverflow.com/questions/11339349/get-coordinates-for-given-location

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!