在javascript中从纬度和经度获取zipcode
要从该位置的纬度和经度显示该位置的邮政编码。下面是我的代码在javascript中从纬度和经度获取zipcode,javascript,php,jquery,google-maps,Javascript,Php,Jquery,Google Maps,要从该位置的纬度和经度显示该位置的邮政编码。下面是我的代码 function markerLocation() { var currentLocation = marker.getPosition(); var geocoder = new google.maps.Geocoder(); var location = new google.maps.LatLng(currentLocation.lat(), currentLocation.lng());
function markerLocation() {
var currentLocation = marker.getPosition();
var geocoder = new google.maps.Geocoder();
var location = new google.maps.LatLng(currentLocation.lat(), currentLocation.lng());
geocoder.geocode({ 'latLng': location , function (results, status) {
if (status == google.maps.GeocoderStatus.OK) {
var add = results[0].address_components[1][1];
document.getElementById('lat').value = add;
}
});
这里我想用lat显示邮政编码。但是当我使用address_组件时,它显示未定义。
请帮忙。试试这个:
<input id="postal_code"/>
<input id="street"/>
...
试试这个:
<input id="postal_code"/>
<input id="street"/>
...
PHP在哪里?显示
结果
数组内容。这可能会对您有所帮助。您需要解析结果才能找到类型为postal\u code的address\u components条目,它不会总是results[0]。address\u components[1][1]
PHP在哪里?显示结果
数组内容。这可能会对您有所帮助。您需要分析结果才能找到类型为postal\u code的address\u components条目,它并不总是results[0]。address\u components[1][1]