电容器 - 地理定位不适用于 iOS,但适用于 Android

Mat*_*att 0 geolocation ios ionic-framework capacitor

我正在编写一个使用地理定位的应用程序。一切都在网络和 Android 上完美运行。但是,在 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.)"}
Run Code Online (Sandbox Code Playgroud)

这是我获取位置的方法:

 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();
            });
    }
Run Code Online (Sandbox Code Playgroud)

你知道什么可能导致这种情况吗?

小智 5

我遇到了同样的问题。在模拟器中单击“功能”>“位置”>“自定义位置”并设置一个位置,为我解决了该问题。希望这可以帮助!