最新消息:Welcome to the puzzle paradise for programmers! Here, a well-designed puzzle awaits you. From code logic puzzles to algorithmic challenges, each level is closely centered on the programmer's expertise and skills. Whether you're a novice programmer or an experienced tech guru, you'll find your own challenges on this site. In the process of solving puzzles, you can not only exercise your thinking skills, but also deepen your understanding and application of programming knowledge. Come to start this puzzle journey full of wisdom and challenges, with many programmers to compete with each other and show your programming wisdom! Translated with DeepL.com (free version)

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

matteradmin8PV0评论

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.

Post a comment

comment list (0)

  1. No comments so far