javascript - Google places autocomplete is not returning correct places - Stack Overflow

I followed the following tutorial:And, the resulting code I wrote has the following instantiation for t

I followed the following tutorial:

And, the resulting code I wrote has the following instantiation for the google places autoplete (I'm using Node.js with browserify so it looks a little different):

enableAutoCompleteForElement: function(aDomElement) {
    var self = this;

    // The geocode type restricts the search to geographical location types.
    GoogleMapsLoader.KEY = ArbitratorConfig.google_api_key;
    GoogleMapsLoader.LIBRARIES = ['places'];
    GoogleMapsLoader.SENSOR = false;

    console.log("Google client id: " + ArbitratorConfig.google_client_id);

    GoogleMapsLoader.load(function(google) {
      self.autoplete = new google.maps.places.Autoplete(aDomElement,
                                                              { types: ['geocode'] });
      google.maps.event.addListener(self.autoplete, 'place_changed', function() {
        // When the user selects an address from the dropdown, this will fire.
        var place = self.autoplete.getPlace();
      });
    });
  }

This works quite well, for most applications. However, I've noticed that it's not quite as accurate as the places autoplete bundled with Google Calendar. For example, if I create an event in Google Calendar and do a search in the location input for 'Bloomington Ice Garden', it will (probably depending on your location to start with) return a result of 'Bloomington Ice Garden, West 98th Street, Minneapolis, MN, United States'. However, if I perform the same search with my client, it doesn't bring up this result. The closest I can get is 'Bloomington, MN, United States'.

I feel like I'm missing part of the library, or I'm incorrectly telling it to do something that it shouldn't be doing. I'd like to be able to retrieve any type of place that's registered with Google Places - not just cities, states, or countries (which appears to be what it's autopleting currently).

I followed the following tutorial:

https://developers.google./maps/documentation/javascript/examples/places-autoplete-addressform

And, the resulting code I wrote has the following instantiation for the google places autoplete (I'm using Node.js with browserify so it looks a little different):

enableAutoCompleteForElement: function(aDomElement) {
    var self = this;

    // The geocode type restricts the search to geographical location types.
    GoogleMapsLoader.KEY = ArbitratorConfig.google_api_key;
    GoogleMapsLoader.LIBRARIES = ['places'];
    GoogleMapsLoader.SENSOR = false;

    console.log("Google client id: " + ArbitratorConfig.google_client_id);

    GoogleMapsLoader.load(function(google) {
      self.autoplete = new google.maps.places.Autoplete(aDomElement,
                                                              { types: ['geocode'] });
      google.maps.event.addListener(self.autoplete, 'place_changed', function() {
        // When the user selects an address from the dropdown, this will fire.
        var place = self.autoplete.getPlace();
      });
    });
  }

This works quite well, for most applications. However, I've noticed that it's not quite as accurate as the places autoplete bundled with Google Calendar. For example, if I create an event in Google Calendar and do a search in the location input for 'Bloomington Ice Garden', it will (probably depending on your location to start with) return a result of 'Bloomington Ice Garden, West 98th Street, Minneapolis, MN, United States'. However, if I perform the same search with my client, it doesn't bring up this result. The closest I can get is 'Bloomington, MN, United States'.

I feel like I'm missing part of the library, or I'm incorrectly telling it to do something that it shouldn't be doing. I'd like to be able to retrieve any type of place that's registered with Google Places - not just cities, states, or countries (which appears to be what it's autopleting currently).

Share Improve this question asked Jan 14, 2016 at 4:45 jwir3jwir3 6,2195 gold badges51 silver badges98 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 8

Remove the types: ['geocode'] option from your Autoplete. That's what's causing Google Places Autoplete to exclude places like 'Bloomington Ice Garden', which is an establishment and not a geocode.

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745645608a4637951.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信