2017-09-20 3 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

예. 나는 그렇게했다. 그래도 작동이 안되는. :/ –

관련 문제