2017-04-06 45 views
-1

時dragend地圖(但工作,如果dragend標記),我不能讓地址獲取地址時,地圖移動

google.maps.event.addListener(map, 'dragend', function(event) { 
myMarker.setPosition(this.getCenter()); // set marker position to map center 

updatePosition(this.getCenter().lat(), this.getCenter().lng()); 

的jsfiddle

http://jsfiddle.net/turq2myw/

回答

0

您需要通過在地圖座標拖動以獲取此事件的地址不包含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); 
     } 
    } 
    }); 

請參見此FIDDLE

+0

工程就像一個魅力..謝謝! ,我可以爲中心地圖的搜索地址添加輸入類型=「文本」嗎? – Edofx

+0

@Edofx沒有得到你能解釋嗎? –

+0

檢查小提琴http://jsfiddle.net/bt4dmu1f/,在搜索框,可以輸入地址,如果找到了,地圖地址居中。 – Edofx