2012-03-30 54 views
0

我想刷新Google地圖併發送新的地理定位請求,而無需刷新頁面,同時用戶在輸入時鍵入地址(城市和地址,國家不變)。我怎樣才能做到這一點?如何在輸入地址時輸入新的地理定位請求並刷新Google地圖?

<input type="text" id="input_adress" /> 
<script type="text/javascript"> 
function mapk() { 
//code about start the map (new google.maps.Map)... 
geokoder.geocode({address: 'UK'}, start_geocode); 
} 
function start_geocode(var1, status) {  
//more code...  
</script> 

現在是我要開始代碼:

$(function() 
    {$('#input_adress').keyup(function() { 

     }); 
    }); 

我不知道應該怎樣下?可能我需要先選擇地圖...

geokoder.geocode({address: 'UK '+$('#input_adress').val()}, start_geocode); 

我在我的頁面上有jQuery庫。這夠了嗎?

回答

1

嘗試這樣:

$('#clickme').click(function() { 
    geocoder.geocode({'address': $('#input_address').val()}, function(results, status) { 
     setMap(results[0].geometry.location.lat(), results[0].geometry.location.lng()); 
    }) 
}); 

function setMap(lat, lng) { 
    map_location = new google.maps.LatLng(lat, lng); 
    marker.setPosition(map_location); 
    map.setCenter(map_location); 
} 

這款採用click上的按鈕進行搜索,但你可以輸入使用按鍵/變化。

Working example here

1

Ussually現場搜索/查詢我要做的就是監控用戶輸入的keydown,時有停頓表明用戶在輸入完成後,那麼我會處理用戶輸入。

的onkeydown:

clearTimeout(timer); timer = setTimeout(function(){ process(); }, 500);

相關問題