无法将Webpack与load-google-maps-api-2一起使用读取未定义的属性“自动完成”

布莱恩·德林格

我正在尝试使用地图javascript api地方自动完成功能来设置自动完成功能,但我一直收到。

未捕获(承诺)TypeError:无法读取未定义的属性“自动完成”

index.js

var loadGoogleMapsApi = require('load-google-maps-api-2');
const indexTemplate = require("./index.handlebars");

    $(function() {

        let googleMaps = null;

        loadGoogleMapsApi({
            key: 'My api key here'
        }).then(function(_googleMaps) {
            googleMaps = _googleMaps
            var autocomplete = new googleMaps.places.Autocomplete($("#address")[0]);

                googleMaps.event.addListener(autocomplete, 'place_changed', function() {
                    var place = autocomplete.getPlace();
                    console.log(place.address_components);
            });
        });

完整的清单在这里。

https://github.com/bryandellinger/addressvalidator

如果要在下载npm后运行它,请安装npm run build(执行webpack构建)npm run start(启动lite服务器并在端口3000上打开浏览器)

马丁·齐特勒

您需要加载places库;根据文档

loadGoogleMapsApi({
    libraries: ['places'],
    key: '...'
})
.then(function (googleMaps) {
  ...
})
.catch(function (error) {
    ...
});

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

如何将Webpack与Google Maps API结合使用?

Google Maps Api v3-getBounds未定义

Android Google Maps API无法与debug.keystore一起使用

提供API密钥后,Google Maps将无法使用/此页面无法显示Google Maps元素

Uncaught TypeError:无法读取未定义的Google Maps的属性“ apply”

Google Maps API Geocoder无法运作

将Android Google Maps v2与自定义View或ImageView一起使用

未捕获的TypeError:无法读取未定义的Google Maps API的属性“ x”

使用Google Maps API自动填写地址

反应开玩笑的测试。无法使用Google JS API读取未定义的属性“地图”

“无法设置未定义的属性'jwtClient'”尝试将Node.js与Google表格一起使用

添加带有react的Google Maps时出错-TypeError:无法读取未定义的属性“ maps”

无法连接到Google Maps Api Android V2

Google Maps Android API自动完成

使用Google Maps API自动完成国家/地区列表

使用php的Google Maps Api

无法使AngularJS Google Map居中/ AngularJS Google Maps API的使用

Google Maps API gm_bindings_未定义

提供API密钥后,Google Maps将无法使用

Google Maps API V3地方信息库无法读取未定义的属性“位置”

Google Maps api标记未定义错误

Google Maps API返回“未定义”

Google Maps Places自动完成-未捕获的TypeError:无法读取未定义的属性“ getPlace”

Google Maps自动补全API

Google Charts API:无法读取未定义的属性“ toArrays”

Google Maps API - 自动完成英国县

Google Drive API - 无法读取未定义的属性“OAuth2”

离子谷歌地图api自动完成无法读取未定义的属性“自动完成”

× TypeError:无法读取未定义的属性“地图” - google.maps 未定义(React)