我需要将经纬度坐标转换为地址。我可以使用Google Maps API,但我需要一个XML响应。
我查看了Convert Lat Long to address Google Maps ApiV2,但我需要在JavaScript中完成此操作。
我的问题是:如何将经纬度坐标转换为地址?
我需要将经纬度坐标转换为地址。我可以使用Google Maps API,但我需要一个XML响应。
我查看了Convert Lat Long to address Google Maps ApiV2,但我需要在JavaScript中完成此操作。
我的问题是:如何将经纬度坐标转换为地址?
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#的源代码,对我起作用了。
您可以使用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>
这是另一种方法。您可以使用以下Google API获取地址,例如JSON脚本。您可以在应用程序中解析它以获取地址。