【发布时间】:2018-08-28 12:05:50
【问题描述】:
我想从经度和纬度中获取用户的城市、州、邮政编码。我遵循了一些来自stackoverflow的关于谷歌地图反向地理编码API的教程,但它有时会返回长度为2到3的数组,长度为6到8的数组。所以我无法准确在哪个索引中我可以找到城市、州和邮政编码。下面是我获取用户经度和纬度的代码。
var longitude,latitude;
if(navigator.geolocation){
navigator.geolocation.getCurrentPosition(showPosition);
} else {
console.log("Geolocation is not supported by this browser.");
}
function showPosition(position) {
longitude = position.coords.longitude;
latitude = position.coords.latitude;
}
谢谢。
【问题讨论】:
-
刚拿到第一个结果我就有很好的经验
-
你应该检查反向地理编码
-
各位读者,请在下注前仔细阅读我的问题。我知道可以通过地理编码实现。