{ this.mapInitialised = true;//part 1 ...">

Ionic 2 Download map "Incomprehensible (in promise): [object PositionError]"

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

      });

    });

  }
+4
source share
2 answers

Suggesting to try to get your error like:

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

You will get the correct error message by doing this.

+1
source

You need to catch a mistake and do something with it. To do this, add an error. The code to fix your problem is here:

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
source

Source: https://habr.com/ru/post/1677162/


All Articles