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);
});
});
}
You need to catch the error and do something with it. To do that an error catch needs to be added. 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));
});
});
}
Suggesting you to try to get your error as:
this.geolocation.getCurrentPosition().then(
(position) => {
/* your code */
} err =>{
alert('Error message : '+ err.message);
});
You will get proper error message by doing this.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With