jwi*_*ir3 1 javascript google-maps autocomplete google-places-api
我按照以下教程:
https://developers.google.com/maps/documentation/javascript/examples/places-autocomplete-addressform
并且,我编写的结果代码具有以下实例化谷歌地方自动完成(我使用带有browserify的Node.js,所以它看起来有点不同):
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.autocomplete = new google.maps.places.Autocomplete(aDomElement,
{ types: ['geocode'] });
google.maps.event.addListener(self.autocomplete, 'place_changed', function() {
// When the user selects an address from the dropdown, this will fire.
var place = self.autocomplete.getPlace();
});
});
}
Run Code Online (Sandbox Code Playgroud)
对于大多数应用程序,这非常有效.但是,我注意到它并不像Google日历捆绑的地方自动完成一样准确.例如,如果我在Google日历中创建一个事件并在"Bloomington Ice Garden"的位置输入中搜索,它将(可能取决于您的位置开始)返回'Bloomington Ice Garden,West 98th Street的结果,明尼阿波利斯,明尼苏达州,美国.但是,如果我使用我的客户端执行相同的搜索,则不会显示此结果.我能得到的最近的是'布卢明顿,明尼苏达州,美国'.
我觉得我错过了图书馆的一部分,或者我错误地告诉它做一些不应该做的事情.我希望能够检索在Google商家信息中注册的任何类型的地方 - 不仅仅是城市,州或国家/地区(目前看来是自动填充的内容).