Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/272.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在javascript中从纬度和经度获取zipcode_Javascript_Php_Jquery_Google Maps - Fatal编程技术网

在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]