如何在android中使用openstreetmap按纬度和经度获取城市名称 [英] How to get the city name by latitude and longitude using openstreetmap in android

查看:80
本文介绍了如何在android中使用openstreetmap按纬度和经度获取城市名称的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的应用程序中,我使用的是 osm 而不是谷歌地图.我有纬度和经度.所以从这里我将如何查询以从 osm 数据库中获取城市名称..请帮助我.我正在使用 osmdroid-android-3.0.8.我需要为此下载任何额外的库吗?

In my app i am using osm rather than google map.I have latitude and longitude.So from here how i will query to get the city name from osm database..plz help me.I am using osmdroid-android-3.0.8.is there any extra library i have to download for this?

推荐答案

这可以通过 反向地理编码,您可以在其中将纬度/经度点转换为人类可读的地址.通常,反向地理编码是作为网络请求完成的.

This can be done through Reverse Geocoding, where you convert a Latitude/Longitude point into a human readable address. Typically, reverse geocoding is done as a web-request.

就您而言,Open Street Maps 有一个 反向地理编码 API,您可以在其中可以向他们的 Web 服务发出请求,然后使用 xml/json 响应来获取城市名称.

In your case, Open Street Maps has a reverse geocoding API where you can make requests to their web service and then consume the xml/json response to get the city name.

向 osm Web 服务发出反向地理编码请求将如下所示:

Making reverse geocode request to the osm web service would look something like this:

http://nominatim.openstreetmap.org/reverse?format=xml&lat=[LATITUDE]&lon=[LONGITUDE]&zoom=18&addressdetails=1

地点:

  • [LATITUDE] 是要进行反向地理编码的纬度点.
  • [LONGITUDE] 是要进行反向地理编码的经度点.

这会给你一个看起来像这样的结果:

This will give you a result that looks something like so:

<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 文档进行处理以查找城市名称节点.

You can then process the result as an xml document to find the city name node.

另一种方法是使用 Google 的地理定位 API.

这篇关于如何在android中使用openstreetmap按纬度和经度获取城市名称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆