将纬度/经度转换为地址

3

我需要将经纬度坐标转换为地址。我可以使用Google Maps API,但我需要一个XML响应。 我查看了Convert Lat Long to address Google Maps ApiV2,但我需要在JavaScript中完成此操作。
我的问题是:如何将经纬度坐标转换为地址?

3个回答

2
var geocoder  = new google.maps.Geocoder();             // create a geocoder object
var location  = new google.maps.LatLng(position.coords.latitude, position.coords.longitude);    // turn coordinates into an object          
geocoder.geocode({'latLng': location}, function (results, status) {
if(status == google.maps.GeocoderStatus.OK) {           // if geocode success
var add=results[0].formatted_address;         // if address found, pass to processing function
document.write(add);

来自https://gist.github.com/marchawkins/9406213/download#的源代码,对我起作用了。


2

您可以使用GeoNames的FindNearestAddress

它需要一个经度和纬度参数,并以XML格式返回最近的地址。

从示例中可以看出:

http://api.geonames.org/findNearestAddress?lat=37.451&lng=-122.18&username=demo

<address>
 <street>Roble Ave</street>
  <mtfcc>S1400</mtfcc>
  <streetNumber>649</streetNumber>
  <lat>37.45127</lat>
  <lng>-122.18032</lng>
  <distance>0.04</distance>
  <postalcode>94025</postalcode>
  <placename>Menlo Park</placename>
  <adminCode2>081</adminCode2>
  <adminName2>San Mateo</adminName2>
  <adminCode1>CA</adminCode1>
  <adminName1>California</adminName1>
  <countryCode>US</countryCode>
 </address>
</geonames>

你知道是否有任何API可以提供更精确的地址吗? - user2574350
这就是我所知道的,抱歉。 - Jeroen Vannevel
抱歉,我没有看到它提供了街道号码,再次感谢。 - user2574350

0

请记住将原始坐标和目的地坐标替换为您自己的坐标。希望这能对您有所帮助。:-) - Jobin Philip

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接