admin管理员组文章数量:1434956
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 badges1 Answer
Reset to default 8Remove 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.
本文标签: javascriptGoogle places autocomplete is not returning correct placesStack Overflow
版权声明:本文标题:javascript - Google places autocomplete is not returning correct places - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745645608a2668116.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论