Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/google-maps/4.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 移动地图时获取地址_Javascript_Google Maps_Google Maps Api 3 - Fatal编程技术网

Javascript 移动地图时获取地址

Javascript 移动地图时获取地址,javascript,google-maps,google-maps-api-3,Javascript,Google Maps,Google Maps Api 3,当dragend映射时,我无法获取地址(但如果dragend标记,则工作) JSFIDLE 您需要在地图拖动中传递坐标以获得地址,就像此事件不包含latlng一样 geocoder.geocode({ 'latLng': this.center }, function(results, status) { if (status == google.maps.GeocoderStatus.OK) { if (results[0]) { var

当dragend映射时,我无法获取地址(但如果dragend标记,则工作)

JSFIDLE


您需要在地图拖动中传递坐标以获得地址,就像此事件不包含latlng一样

geocoder.geocode({
       'latLng': this.center
  }, function(results, status) {
    if (status == google.maps.GeocoderStatus.OK) {
      if (results[0]) {
        var alamat = results[0].formatted_address; 
            document.getElementById("alamat").value = alamat;
     // alert(alamat);
      }
    }
  });

看到了吗

效果很好。。谢谢我可以为中心地图的搜索地址添加输入type=“text”吗?@Edofx没有得到您可以解释吗?选中搜索框中的fiddle,可以键入地址,如果找到,以地址为中心的地图。您的意思是从地址和中心地图获得坐标是正确的吗?检查我的脚本,可能是错误的。未定义控制台locateAddress处的get错误。出什么事了?
geocoder.geocode({
       'latLng': this.center
  }, function(results, status) {
    if (status == google.maps.GeocoderStatus.OK) {
      if (results[0]) {
        var alamat = results[0].formatted_address; 
            document.getElementById("alamat").value = alamat;
     // alert(alamat);
      }
    }
  });