2017-09-20 6 views
1

元気?私はIonic 3チュートリアルのGoogle Mapsを勉強しています。私はそこに説明されていることをすべて実行しましたが、プロジェクトが開始されると、このエラーが表示されます。私は多くを調査しましたが、何も機能しません。ありがとう!IONIC 3:未知(約束):ReferenceError:Googleが定義されていないReferenceError

home.tsあなたのコードであることをしなかったところ以下のようにあなたがdeclareにそれを必要とする

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

で同じ問題について

declare var google: any; 

これはコルドバのプラグインですか?あなたは装置で走っていますか? –

+0

いいえ。ノートパソコンのブラウザ。はい、コードワプラグインです。 –

+0

コードワインプラグインには「イオンサービング」が搭載されていません。エミュレータ/デバイス –

答えて

0

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

は、これは私のコードです。 Git repo

+0

OPはすでにそれを追加しているようです –

+0

しかし、それを 'any'として宣言していません@suraj – Sampath

+0

私はそれをそのように置いた。まだ動かない。 :/ –

関連する問題