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).
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With