Capacitor - 地理定位在iOS上不工作,但在Android上可以工作。

问题描述 投票:0回答:1

我正在编写一个使用地理位置的应用程序。然而,在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();
            });
    }

你知道是什么原因吗?

ios ionic-framework geolocation capacitor
1个回答
4
投票

我遇到了同样的问题。在模拟器中点击功能> 位置> 自定义位置,并在那里设置一个位置,为我解决了这个问题。希望这能帮到你

© www.soinside.com 2019 - 2024. All rights reserved.