【问题标题】:ionic 3 google maps Cannot read property 'Autocomplete' of undefined离子 3 谷歌地图无法读取未定义的属性“自动完成”
【发布时间】:2017-12-13 04:56:59
【问题描述】:

目前我正在从事 ionic 3 项目,我可以使用谷歌地图,我想使用谷歌地点自动完成功能,我使用这个答案 Answer 来解决问题“找不到名称 google”,当我输入 let input = new google.maps.places.Autocomplete(element);

它工作了,现在应用程序运行了,但现在我得到了新的错误

'ERROR TypeError: Cannot read property 'Autocomplete' of undefined'

我该怎么办?

编辑(1)

当我使用console.log(google.maps); 时,我得到了结果,但是当我使用console.log(google.maps.places); 时,我得到了未定义。

但是当我在 VSCode 中点击places时,它显示它存在

    export module places {
        export class Autocomplete extends MVCObject {
            constructor(inputField: HTMLInputElement, opts?: AutocompleteOptions);
            getBounds(): LatLngBounds;
            getPlace(): PlaceResult;
            setBounds(bounds: LatLngBounds|LatLngBoundsLiteral): void;
            setComponentRestrictions(restrictions: ComponentRestrictions): void;
            setTypes(types: string[]): void;
        }
etc etc

【问题讨论】:

    标签: google-maps ionic-framework autocomplete ionic3


    【解决方案1】:

    您必须在 index.html 中包含以下代码行

    注意:如果你有一个现有的谷歌地图 javascript,你需要用这个替换它

    <script src="https://maps.googleapis.com/maps/api/js?v=3.exp&libraries=places&key=YOUR_KEY"></script>
    

    其中:YOUR_KEY 是您的开发者密钥

    【讨论】:

      猜你喜欢
      • 2017-04-03
      • 1970-01-01
      • 2017-11-09
      • 2020-10-04
      • 2021-11-03
      • 1970-01-01
      • 2018-04-06
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多