Answer the question
In order to leave comments, you need to log in
How to implement google place autocomplete hints for a specific city?
Hello !
I am developing a taxi application. You need to do a search (where to go) with hints google place autocomplete. The problem is that I can not set the search boundary within the city (For example: Moscow). With the help of bounds, everything works, but when searching, addresses in other cities (St. Petersburg, etc.) are also given, but I only need in Moscow.
I will give the code working on bounds but without exact boundaries:
navigator.geolocation.getCurrentPosition(function(position) {
new google.maps.Geocoder().geocode( { 'latLng': new google.maps.LatLng(position.coords.latitude, position.coords.longitude) }, function(results, status) {
if (status == google.maps.GeocoderStatus.OK) {
angular.forEach(results[0].address_components, function(value, key) {
if(value.types[0] == "locality"){
new google.maps.Geocoder().geocode( { 'address': "Черкесск" }, function (results_locality, status) {
var bounds = JSON.parse(JSON.stringify(results_locality[0].geometry.bounds));
autocomplete.setBounds(new google.maps.LatLngBounds(
new google.maps.LatLng(bounds.south, bounds.west),
new google.maps.LatLng(bounds.north, bounds.east)
));
});
}
});
} else {
console.log("Geocode was not successful for the following reason: " + status);
}
});
},function(error){
console.log(error);
});
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question