<分区>
在我的应用程序中,我使用的是 osm 而不是谷歌地图。我有纬度和经度。所以从这里我将如何查询从 osm 数据库中获取城市名称。请帮助我。我正在使用 osmdroid-android-3.0 .8.是否需要为此下载任何额外的库?
<分区>
在我的应用程序中,我使用的是 osm 而不是谷歌地图。我有纬度和经度。所以从这里我将如何查询从 osm 数据库中获取城市名称。请帮助我。我正在使用 osmdroid-android-3.0 .8.是否需要为此下载任何额外的库?
最佳答案
这可以通过 Reverse Geocoding 完成,您可以在其中将纬度/经度点转换为人类可读的地址。通常,反向地理编码是作为网络请求完成的。
在您的例子中,Open Street Maps 有一个 reverse geocoding API您可以在其中向他们的 Web 服务发出请求,然后使用 xml/json 响应来获取城市名称。
向 osm 网络服务发出反向地理编码请求看起来像这样:
http://nominatim.openstreetmap.org/reverse?format=xml&lat=[LATITUDE]&lon=[LONGITUDE]&zoom=18&addressdetails=1
地点:
这会给你一个看起来像这样的结果:
<reversegeocode timestamp="Fri, 06 Nov 09 16:33:54 +0000" querystring="...">
<result place_id="1620612" osm_type="node" osm_id="452010817">
135, Pilkington Avenue, Wylde Green, City of Birmingham, West Midlands (county), B72, United Kingdom
</result>
<addressparts>
<house>135</house>
<road>Pilkington Avenue</road>
<village>Wylde Green</village>
<town>Sutton Coldfield</town>
<city>City of Birmingham</city>
<county>West Midlands (county)</county>
<postcode>B72</postcode>
<country>United Kingdom</country>
<country_code>gb</country_code>
</addressparts>
</reversegeocode>
然后您可以将结果处理为 xml 文档以查找城市名称节点。
另一种方法是使用 Google's Geolocation API .
关于android - 如何在android中使用openstreetmap按经纬度获取城市名称,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18487957/
相关文章:
android - 使用 osmbonuspack 启动点击 MarkerInfoWindow 的 Intent
javascript - 如何在 openstreetmap 中获取当前缩放级别?
java - 为什么公共(public)类在 android 开发人员滑动 View 示例中的同一个文件中?
android - osmdroid、Maps API v2 和 fragment
python - 如何使用 OSMNx/Networkx 添加边长度作为中间中心性的权重?
javascript - 具有 {key : 'theKey' , value: 'theValue' } 对象的数组