2017-05-15 5 views
4
initMap(): Promise<any> { 

    this.mapInitialised = true;//part 1 

    return new Promise((resolve) => { 


     this.geolocation.getCurrentPosition().then((position) => {// Part 2 

    let latLng = new google.maps.LatLng(position.coords.latitude,position.coords.longitude); 

     let mapOptions = { 
      center: latLng, 
      zoom: 15, 
      mapTypeId: google.maps.MapTypeId.ROADMAP 
     } 

     this.map = new google.maps.Map(this.mapElement, mapOptions); 
     resolve(true); 

     }); 

    }); 

    } 
+0

これは、https://stackoverflow.com/questions/41834382/ionic2-geolocation-in-browser-fails-with-error-exception-uncaught-in-promiseの複製である可能性があります。 – CrazyPyro

答えて

0

エラーをキャッチして何かを行う必要があります。そのためにはエラーキャッチを追加する必要があります。あなたの問題を解決するためのコードはここにある:

としてあなたのエラーを取得しようとするあなたの提案
initMap(): Promise<any> { 
    this.mapInitialised = true;//part 1 
    return new Promise((resolve) => { 
     this.geolocation.getCurrentPosition().then(
      (position) => {// Part 2 
      let latLng = new google.maps.LatLng(position.coords.latitude, position.coords.longitude); 
      let mapOptions = { 
       center: latLng, 
       zoom: 15, 
       mapTypeId: google.maps.MapTypeId.ROADMAP; 
      } 

      this.map = new google.maps.Map(this.mapElement, mapOptions); 
      resolve(true); 
     }, 
     // Here is the error catching that needs to be added 
     err =>{ 
      console.log(' Error : ' + JSON.stringify(error)); 
     }); 
    }); 
} 
0

:あなたはこれを行うことにより、適切なエラー・メッセージが表示されます

this.geolocation.getCurrentPosition().then(
(position) => { 
    /* your code */ 
} err =>{ 
     alert('Error message : '+ err.message); 
}); 

関連する問題