IONIC 3: Uncaught (in promise): ReferenceError: google is not defined ReferenceError [英] IONIC 3: Uncaught (in promise): ReferenceError: google is not defined ReferenceError

查看:64
本文介绍了IONIC 3: Uncaught (in promise): ReferenceError: google is not defined ReferenceError的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好吗?我正在学习带有 Ionic 3 的 Google 地图教程.我已经完成了那里解释的一切,但是当项目启动时,出现了这个错误.我调查了很多,但没有任何效果.谢谢!.

How are you?. I am studying a Google Maps with Ionic 3 tutorial. I have done everything what is explained there, but when the project is launched, there is appearing this error. I have investigated A LOT, but nothing works. Thanks!.

Error: Uncaught (in promise): ReferenceError: google is not defined
ReferenceError: google is not defined

这是我的代码:

home.ts

import { Component, ViewChild, ElementRef } from '@angular/core';
import { NavController } from 'ionic-angular';
import { IonicPage } from 'ionic-angular';

declare var google;

@IonicPage()
@Component({
selector: 'page-home',
templateUrl: 'home.html'
})
export class HomePage {

    @ViewChild('map') mapElement:ElementRef;
    map: any;
    start = 'chicago, il';
    end = 'chicago, il';
    directionsService = new google.maps.DirectionsService;
    directionsDisplay = new google.maps.DirectionsRenderer;

    constructor(public navCtrl: NavController) {

    }

    ionViewLoad(){
        this.initMap();
    }

    initMap(){
        this.map = new google.maps.Map(this.mapElement.nativeElement, 
    { 
            zoom: 7,
            center: {lat: 41.85, lng: -87.65}
    });

        this.directionsDisplay.setMap(this.map);
    }

    calculateAndDisplayRoute(){
        this.directionsService.route({
            origin: this.start,
            destination: this.end,
            travelMode: 'DRIVING',
        }, (response, status) => {
            if(status == 'OK'){
                this.directionsDisplay.setDirections(response);
            }else{
                window.alert('Directions request failed due to ' + 
        status);
            }
        });
        }

     }

推荐答案

确保在加载javascript时使用HTTPS!

Make sure you use HTTPS when loading javascript!

从此改变

<script src="http://maps.googleapis.com/maps/api/js?key=YOUR_API_KEY"></script>

<script src="https://maps.googleapis.com/maps/api/js?key=YOUR_API_KEY"></script>

这篇关于IONIC 3: Uncaught (in promise): ReferenceError: google is not defined ReferenceError的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆