{ -6ren">
gpt4 book ai didi

google-maps - ionic 2 map 加载 "Uncaught (in promise): [object PositionError]"

转载 作者:行者123 更新时间:2023-12-04 16:47:03 25 4
gpt4 key购买 nike

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

});

});

}

最佳答案

您需要捕获错误并对其进行处理。为此,需要添加错误捕获。解决问题的代码在这里:

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

关于google-maps - ionic 2 map 加载 "Uncaught (in promise): [object PositionError]",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43977280/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com