Offline reverse geocoding on iOS

跟風遠走 提交于 2019-12-22 01:04:06

问题


There are lots of existing questions relating to this issue, but I have looked at as many of them as I could find and did not get an answer.

I'm trying to perform an offline reverse geocoding lookup on iOS based on a latitude and longitude. I'd like to be able to provide a latitude and longitude, and be provided with the country in which that point lies. I can do this with Geonames (such as: http://api.geonames.org/countryCode?lat=45.03&lng=8.2&username=demo), but I need a similar ability offline, without Internet functionality on the device.

CLLocation does not provide offline services that work reliably enough for what I'm doing, it relies on caches made while you were previously online, etc. Messy.

I've tried this: https://github.com/drodriguez/reversegeocoding but haven't had any luck, it requires some slightly complex / confusing Terminal installations using something called Thor which I've never heard of, and was throwing up a variety of errors, so I bailed on it.

I've found a few downloadable maps, but these seem to be even more complicated, and worryingly, hundreds of megabytes or even gigabytes in size – much beyond the scope of an iOS app. I only need countries, nothing smaller than that (cities, streets, locations, etc.) so I think I should be able to get a much smaller file.

So my key question is: is there some pre-existing database or tool, preferably with iOS support, that I can feed a latitude/longitude, and get a country? And, if not, what steps should I take to get such functionality working on my own?

Thanks in advance.


回答1:


ReverseGeocodeCountry is a simple lightweight offline country reverse geocoder for iOS, it has a static JSON file with country polygon data that is used to reverse geocode any lat/lng:

https://github.com/krisrak/ios-offline-reverse-geocode-country




回答2:


The "Countries of the World" is a .csv text file with countries, coordinates, localised country names, capitals and other information. It seems to be free to use. You just have to import it into an SQLite database.

Edit Just noticed you want reverse geocoding. The database would only be good for forward geocoding.

You can download shapefiles for all countries at http://www.gadm.org/download. If you download a .kmz, you can unpack it to a list of coordinates for the borders. You could probably take every 5th or 10th coordinate to get smaller size (with less accuracy).




回答3:


Just in case I can suggest another good written offline geocoding library. https://github.com/Alterplay/APOfflineReverseGeocoding



来源:https://stackoverflow.com/questions/14588778/offline-reverse-geocoding-on-ios

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