如何使用纬度和经度获取位置名称或城市?

13

我正在使用以下代码,但如何从经度和纬度中获取城市名称或位置名称?

var x=document.getElementById("location");
function getLocation()
{
    if (navigator.geolocation) {
        navigator.geolocation.getCurrentPosition(showPosition,showError);
    }
    else {
        x.innerHTML="Geolocation is not supported by this browser.";
    }
}

function showPosition(position)
{
    x.innerHTML="Latitude: " + position.coords.latitude + 
        "<br>Longitude: " + position.coords.longitude;  
}

1
http://en.wikipedia.org/wiki/Reverse_geocoding - Roatin Marth
尝试使用谷歌地理编码 API https://developers.google.com/maps/documentation/geocoding/ - rlemon
1个回答

8

但是位置名称没有出现。 - E J Chathuranga

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