我想从经度和纬度获取用户的城市,州,邮政编码。我遵循了stackoverflow上有关Google地图反向地理编码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;
}
谢谢。