2012-03-30 30 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);

相关问题