admin管理员组文章数量:1026087
I would like to have an input field on my website with autoplete for places within a certain country. For example in the code below I want to get only places within the country 'The Netherlands' as suggestions in the autoplete.
In the code below I'm getting suggestions for places in all countries, not specified for a certain country.
<!DOCTYPE html>
<html>
<head>
<title>Google Maps JavaScript API v3 Example: Places Autoplete</title>
<script src=";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 autoplete = new google.maps.places.Autoplete(input, {country: 'NL'});
autoplete.bindTo('bounds', map);
var infowindow = new google.maps.InfoWindow();
var marker = new google.maps.Marker({
map: map
});
google.maps.event.addListener(autoplete, 'place_changed', function() {
infowindow.close();
var place = autoplete.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>
I would like to have an input field on my website with autoplete for places within a certain country. For example in the code below I want to get only places within the country 'The Netherlands' as suggestions in the autoplete.
In the code below I'm getting suggestions for places in all countries, not specified for a certain country.
<!DOCTYPE html>
<html>
<head>
<title>Google Maps JavaScript API v3 Example: Places Autoplete</title>
<script src="http://maps.googleapis./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 autoplete = new google.maps.places.Autoplete(input, {country: 'NL'});
autoplete.bindTo('bounds', map);
var infowindow = new google.maps.InfoWindow();
var marker = new google.maps.Marker({
map: map
});
google.maps.event.addListener(autoplete, 'place_changed', function() {
infowindow.close();
var place = autoplete.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>
Share
Improve this question
edited Nov 9, 2011 at 14:34
duncan
31.9k15 gold badges81 silver badges101 bronze badges
asked Nov 9, 2011 at 14:26
BastiaanWWBastiaanWW
1,2994 gold badges20 silver badges35 bronze badges
2 Answers
Reset to default 2You can set a bias (which you already have) but without actually checking each autoplete result with additional code you cannot limit the autoplete list to a certain country or area, to my knowledge.
Here is some more information on Google's Autoplete: http://code.google./apis/maps/documentation/places/autoplete.html#place_autoplete_requests
Ah, if you want to use the geo-autoplete plugin, then take a look at this example:
view-source:http://geo-autoplete.googlecode./svn/trunk/demo/ui.demo.html
This is from their example:
$('#demo3_location').geo_autoplete({
geocoder_region: 'Africa',
geocoder_types: 'country',
mapheight: 100, mapwidth: 200, maptype: 'hybrid'
});
No need to change anything - you just have to create a Global variable option instead of
{country: 'NL'}
put options
at there.
Now declare Option before use.
options = {types: ['(cities)'],ponentRestrictions: { country: 'US' }};
Now Your line will be:
var autoplete = new google.maps.places.Autoplete(input, options);
Hope work for you - ! Thanks, Kavi (India)
I would like to have an input field on my website with autoplete for places within a certain country. For example in the code below I want to get only places within the country 'The Netherlands' as suggestions in the autoplete.
In the code below I'm getting suggestions for places in all countries, not specified for a certain country.
<!DOCTYPE html>
<html>
<head>
<title>Google Maps JavaScript API v3 Example: Places Autoplete</title>
<script src=";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 autoplete = new google.maps.places.Autoplete(input, {country: 'NL'});
autoplete.bindTo('bounds', map);
var infowindow = new google.maps.InfoWindow();
var marker = new google.maps.Marker({
map: map
});
google.maps.event.addListener(autoplete, 'place_changed', function() {
infowindow.close();
var place = autoplete.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>
I would like to have an input field on my website with autoplete for places within a certain country. For example in the code below I want to get only places within the country 'The Netherlands' as suggestions in the autoplete.
In the code below I'm getting suggestions for places in all countries, not specified for a certain country.
<!DOCTYPE html>
<html>
<head>
<title>Google Maps JavaScript API v3 Example: Places Autoplete</title>
<script src="http://maps.googleapis./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 autoplete = new google.maps.places.Autoplete(input, {country: 'NL'});
autoplete.bindTo('bounds', map);
var infowindow = new google.maps.InfoWindow();
var marker = new google.maps.Marker({
map: map
});
google.maps.event.addListener(autoplete, 'place_changed', function() {
infowindow.close();
var place = autoplete.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>
Share
Improve this question
edited Nov 9, 2011 at 14:34
duncan
31.9k15 gold badges81 silver badges101 bronze badges
asked Nov 9, 2011 at 14:26
BastiaanWWBastiaanWW
1,2994 gold badges20 silver badges35 bronze badges
2 Answers
Reset to default 2You can set a bias (which you already have) but without actually checking each autoplete result with additional code you cannot limit the autoplete list to a certain country or area, to my knowledge.
Here is some more information on Google's Autoplete: http://code.google./apis/maps/documentation/places/autoplete.html#place_autoplete_requests
Ah, if you want to use the geo-autoplete plugin, then take a look at this example:
view-source:http://geo-autoplete.googlecode./svn/trunk/demo/ui.demo.html
This is from their example:
$('#demo3_location').geo_autoplete({
geocoder_region: 'Africa',
geocoder_types: 'country',
mapheight: 100, mapwidth: 200, maptype: 'hybrid'
});
No need to change anything - you just have to create a Global variable option instead of
{country: 'NL'}
put options
at there.
Now declare Option before use.
options = {types: ['(cities)'],ponentRestrictions: { country: 'US' }};
Now Your line will be:
var autoplete = new google.maps.places.Autoplete(input, options);
Hope work for you - ! Thanks, Kavi (India)
本文标签: javascriptGeoAutocomplete for a certain countryStack Overflow
版权声明:本文标题:javascript - Geo-Autocomplete for a certain country - Stack Overflow 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://it.en369.cn/questions/1745629047a2160046.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论