Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Google Maps autocomplete only Streets with Number

I have an website where i want to pinpoint user input to geocoords and using that adresse for something like a meeting.

The problem is that google autocomplete also shows "ZIP-Codes only" or Streets without a streetno.

Is there anyway to filter the autocomplete results before displaying them?

var input = /** @type {HTMLInputElement} */(
            document.getElementById('pac-input'));
var defaultBounds = new google.maps.LatLngBounds(
            new google.maps.LatLng(52.66805480068766, 13.7713623046875),
            new google.maps.LatLng(52.32191088594773, 12.98858642578125));
var autocomplete_options = {
        bounds: defaultBounds,
        componentRestrictions: {country: 'de'},
        types: ['geocode']
    };
    autocomplete = new google.maps.places.Autocomplete(input, autocomplete_options);
    google.maps.event.addListener(autocomplete, 'place_changed', callServer);

My testsite to see the autocomplete can be found here: http://www.winterreifenwechsel.de/welcome/termine

Try some inputs like 14169 (zip code) or Wilskistr (for street without housenumber).

like image 895
Benjamin Eckstein Avatar asked Feb 17 '15 22:02

Benjamin Eckstein


1 Answers

You can use the Place Types parameter in the URL request of the Autocomplete API which accepts only the locations with the geocode. This would enable the autocomplete results based on locations that have a proper lat lang and not a region.

Here is the API request for that:

https://maps.googleapis.com/maps/api/place/autocomplete/json?input=Vict&types;=geocode&language;=fr&key;=API_KEY

For more details please refer to this Google's official doc.

EDIT

Then I would say use the Places Autocomplete address form in your webapp. Here is the link for that which will restrict users to use address which you can pass as lat lng in your ,aps.

like image 104
AniV Avatar answered Oct 16 '22 15:10

AniV