【问题标题】:How do I get location name or city using latitude & longitudes?如何使用纬度和经度获取位置名称或城市?
【发布时间】:2013-03-27 15:29:56
【问题描述】:

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

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

【问题讨论】:

标签: javascript geolocation


【解决方案1】:

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

【讨论】:

  • 但是位置名称没有出现
猜你喜欢
  • 1970-01-01
  • 2013-12-09
  • 1970-01-01
  • 2013-03-03
  • 2017-10-07
  • 2011-09-26
  • 1970-01-01
  • 2011-06-12
相关资源
最近更新 更多