最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Google Maps autocomplete only Streets with Number - Stack Overflow

programmeradmin8浏览0评论

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 autoplete also shows "ZIP-Codes only" or Streets without a streetno.

Is there anyway to filter the autoplete 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 autoplete_options = {
        bounds: defaultBounds,
        ponentRestrictions: {country: 'de'},
        types: ['geocode']
    };
    autoplete = new google.maps.places.Autoplete(input, autoplete_options);
    google.maps.event.addListener(autoplete, 'place_changed', callServer);

My testsite to see the autoplete can be found here:

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

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 autoplete also shows "ZIP-Codes only" or Streets without a streetno.

Is there anyway to filter the autoplete 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 autoplete_options = {
        bounds: defaultBounds,
        ponentRestrictions: {country: 'de'},
        types: ['geocode']
    };
    autoplete = new google.maps.places.Autoplete(input, autoplete_options);
    google.maps.event.addListener(autoplete, 'place_changed', callServer);

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

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

Share Improve this question asked Feb 17, 2015 at 22:42 Benjamin EcksteinBenjamin Eckstein 8942 gold badges9 silver badges19 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 3

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

Here is the API request for that:

https://maps.googleapis./maps/api/place/autoplete/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 Autoplete 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.

发布评论

评论列表(0)

  1. 暂无评论