我想在我的网站上有一个输入字段,并在某个国家/地区的地方自动填充。例如,在下面的代码中,我希望获得国家/地区“荷兰”内的地点作为自动填充中的建议。某个国家/地区的地理自动完成功能
在下面的代码中,我得到了所有国家/地区的地方建议,而不是针对某个国家/地区。
<!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