我想在我的網站上有一個輸入字段,並在某個國家/地區的地方自動填充。例如,在下面的代碼中,我希望獲得國家/地區「荷蘭」內的地點作爲自動填充中的建議。某個國家/地區的地理自動完成功能
在下面的代碼中,我得到了所有國家/地區的地方建議,而不是針對某個國家/地區。
<!DOCTYPE html>
<html>
<head>
<title>Google Maps JavaScript API v3 Example: Places Autocomplete</title>
<script src="http://maps.googleapis.com/maps/api/js?sensor=false&libraries=places"
type="text/javascript"></script>
<style type="text/css">
body {
font-family: sans-serif;
font-size: 14px;
}
#map_canvas {
height: 400px;
width: 600px;
margin-top: 0.6em;
}
</style>
<script type="text/javascript">
function initialize() {
var input = document.getElementById('searchTextField');
var autocomplete = new google.maps.places.Autocomplete(input, {country: 'NL'});
autocomplete.bindTo('bounds', map);
var infowindow = new google.maps.InfoWindow();
var marker = new google.maps.Marker({
map: map
});
google.maps.event.addListener(autocomplete, 'place_changed', function() {
infowindow.close();
var place = autocomplete.getPlace();
if (place.geometry.viewport) {
map.fitBounds(place.geometry.viewport);
} else {
map.setCenter(place.geometry.location);
map.setZoom(17); // Why 17? Because it looks good.
}
});
setupClickListener('changetype-all', []);
}
google.maps.event.addDomListener(window, 'load', initialize);
</script>
</head>
<body>
<div>
<input id="searchTextField" type="text" size="50">
<label for="changetype-all"></label>
</div>
</body>
</html>
在這個鏈接:http://code.google.com/p/geo-autocomplete/它說:geocoder_region ==>過濾建議位置到特定區域,例如, '歐洲'這就是爲什麼我認爲它應該是可能的..我也嘗試過geocoder_region – BastiaanWW
geo-autocomplete需要額外的插件。我已經使用geocoder_region爲您提供了一個更絕對的過濾器的演示程序。 – Derek
這個例子是不工作(FF和IE)我也試過你的代碼與ID:「searchTextField」,但也不工作.. – BastiaanWW