简体   繁体   English

iOS 上的离线反向地理编码

[英]Offline reverse geocoding on iOS

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.我正在尝试基于纬度和经度在 iOS 上执行离线反向地理编码查找。 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.我可以使用 Geonames 来做到这一点(例如: http ://api.geonames.org/countryCode?lat=45.03&lng=8.2&username=demo),但我需要离线类似的功能,设备上没有 Internet 功能。

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. CLLocation没有提供足够可靠的离线服务来完成我正在做的事情,它依赖于您之前在线时制作的缓存,等等。混乱。

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.我试过这个: https ://github.com/drodriguez/reversegeocoding 但没有运气,它需要一些稍微复杂/令人困惑的终端安装,使用我从未听说过的名为 Thor 的东西,并且正在呕吐各种错误,所以我放弃了。

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.我找到了一些可下载的地图,但这些地图似乎更加复杂,令人担忧的是,大小达到数百兆甚至千兆字节——远远超出了 iOS 应用程序的范围。 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?所以我的关键问题是:是否有一些预先存在的数据库或工具,最好是支持 iOS,我可以提供纬度/经度,并获得一个国家? And, if not, what steps should I take to get such functionality working on my own?如果没有,我应该采取哪些步骤来让这些功能自己运行?

Thanks in advance.提前致谢。

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: ReverseGeocodeCountry是一个用于 iOS 的简单轻量级离线国家反向地理编码器,它有一个包含国家多边形数据的静态 JSON 文件,用于对任何 lat/lng 进行反向地理编码:

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

The " Countries of the World " is a .csv text file with countries, coordinates, localised country names, capitals and other information. 世界各国”是一个.csv文本文件,其中包含国家、坐标、本地化国家名称、首都和其他信息。 It seems to be free to use.它似乎可以免费使用。 You just have to import it into an SQLite database.您只需将其导入 SQLite 数据库。

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 .您可以在http://www.gadm.org/download下载所有国家/地区的 shapefile。 If you download a .kmz , you can unpack it to a list of coordinates for the borders.如果您下载.kmz ,您可以将其解压缩到边界坐标列表中。 You could probably take every 5th or 10th coordinate to get smaller size (with less accuracy).您可能会每隔 5 或 10 个坐标获取更小的尺寸(精度更低)。

Just in case I can suggest another good written offline geocoding library.以防万一我可以推荐另一个好的书面离线地理编码库。 https://github.com/Alterplay/APOfflineReverseGeocoding https://github.com/Alterplay/APOfflineReverseGeocoding

This question is duplicated multiple times in SO.这个问题在 SO 中重复了多次。 I have answered this in another question ( https://stackoverflow.com/a/73027520/17219971 ).我已经在另一个问题( https://stackoverflow.com/a/73027520/17219971 )中回答了这个问题。 It is neither an API nor a lib and is platform/language agnostic.它既不是 API 也不是库,并且与平台/语言无关。 Suitable for mobiles apps or offline use.适用于移动应用程序或离线使用。

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

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