Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Google Maps autocomplete but only for street address names

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?

like image 594
NekoSama Avatar asked Apr 16 '12 15:04

NekoSama


People also ask

How do I limit Google autocomplete results to city and country only Android?

How do I limit Google autocomplete results to city only? List only cities in the country var options = { types: ['(cities)'], componentRestrictions: {country: “us”} }; List all cities, states and regions in the country var options = { types: ['(regions)'], componentRestrictions: {country: “us”} };

How does Google address autocomplete work?

Autocomplete predictions reflect real searches that have been done on Google. To determine what predictions to show, our systems look for common queries that match what someone starts to enter into the search box but also consider: The language of the query. The location a query is coming from.

What is address autocomplete?

Address Autocomplete is an address form feature that suggests street addresses to users as they type an address into a form. Because an Autocomplete function reduces the number of keystrokes & mistakes that a user types, it can make data submission faster and more accurate.


1 Answers

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'],
};
like image 153
Vasanth Subramanian Avatar answered Oct 19 '22 01:10

Vasanth Subramanian