2017-09-20 57 views
1

你好吗?我正在学习带有Ionic 3教程的Google Maps。我已经完成了所有解释,但是当项目启动时,出现这个错误。我已经调查了很多,但没有任何工作。谢谢!。IONIC 3:Uncaught(承诺):ReferenceError:google没有定义ReferenceError

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); 
      } 
     }); 
     } 

    } 
+0

同样的问题是这样的一个插件科尔多瓦?你在设备上运行吗? –

+0

号笔记本浏览器。是的,是一个科尔多瓦插件。 –

+0

cordova插件没有加载'ionic serve'。使用模拟器/设备 –

回答

0

你需要declare它如下图所示,你没有这样做,在你的代码。

declare var google: any; 

关于Git repo

+0

OP似乎已经添加了 –

+0

但并未声明它为'any' @suraj – Sampath

+0

是的。我这样说。还是行不通。 :/ –

相关问题