如何使用纬度&经度?

问题描述:

我使用下面的代码,但是如何从经度&域名获取城市名称或地点名称,纬度?

I'm using the below code, but how to get the city name or the location name from the longitude & latitude?

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;  
}


您可以使用Google地图v3 API在经度和纬度对上执行反向地理编码。您可以在这里找到如何执行此操作的示例: https://developers.google.com/maps/documentation / geocoding /#ReverseGeocoding

You can use the Google Maps v3 API to perform reverse geocoding on a latitude and longitude pair. You can find an example of how to do that here: https://developers.google.com/maps/documentation/geocoding/#ReverseGeocoding.