Reputation: 71
I am currently starting to use Google Maps v3 API and I want to know if it is posible to use the autocomplete feature to only autocomplete street address name?
I am currently using this code:
$(document).ready(function(){
var options = {
types: ['(cities)'],
componentRestrictions: {country: "ar" }
};
var input = document.getElementById('laboral_calle');
var autocomplete = new google.maps.places.Autocomplete(input, options);
});
But is not currently working.
I need to set a fixed State and a fixed City to show only street names suggestions in the textfield.
Is it possible?
Upvotes: 7
Views: 2995
Reputation: 91
I'm not sure I fully understand your requirement - are you saying that you want to match only street addresses within a particular city/state?
If so, you can set a LatLngBounds in your autocomplete options to bias all results to within the area your bounds encloses. It won't completely filter out anything outside that, but for a given search, if there's something inside your bounds that matches it, it will appear above anything else. Note that if you set type to '(cities)', it will only match against 'cities', and you won't see any street addresses!
Here I define a LatLngBounds that encompasses London and then restrict the autocomplete to only match street addresses.
var londonBounds = new google.maps.LatLngBounds(new google.maps.LatLng(51.332757,-0.475159),new google.maps.LatLng(51.680219,0.191574));
var autocompleteOptions = {
bounds: londonBounds,
types:['geocode'],
};
Upvotes: 1