我正在编写一个使用地理位置的应用程序。然而,在ios上,我无法获取位置(我已经实现的第二种方法--从地图上选取一个位置,虽然可以)。
我在Xcode控制台得到这个错误。
⚡️ To Native -> Geolocation getCurrentPosition 7620184
ERROR MESSAGE: {"errorMessage":"The operation couldn’t be completed.
(kCLErrorDomain error 0.)","message":"The operation couldn’t be completed.
(kCLErrorDomain error 0.)"}
这是我获取位置的方法。
private locateUser() {
if (!Capacitor.isPluginAvailable('Geolocation')) {
this.showErrorAlert();
return;
}
this.isLoading = true;
Plugins.Geolocation.getCurrentPosition()
.then(geoPosition => {
const coordinates: Coordinates = {
lat: geoPosition.coords.latitude,
lng: geoPosition.coords.longitude
};
this.createPlace(coordinates.lat, coordinates.lng);
this.isLoading = false;
})
.catch(err => {
this.isLoading = false;
this.showErrorAlert();
});
}
你知道是什么原因吗?
我遇到了同样的问题。在模拟器中点击功能> 位置> 自定义位置,并在那里设置一个位置,为我解决了这个问题。希望这能帮到你