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

Capacitor - Geolocation does not work on iOS but works on Android

我正在编写一个使用地理定位的应用程序。在网络和 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.)"}

这是我获取位置的方法:

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

您知道是什么原因造成的吗?

我运行遇到了同样的问题。在模拟器中单击“功能”>“位置”>“自定义位置”并在那里设置一个位置为我解决了这个问题。希望这对您有所帮助!

我遇到了同样的问题。 为了其他目的,我在 config.xml 中设置了一个带有主机名和他的 ip 地址的首选项标签。 删除它解决了地理定位错误