【问题标题】:navigator.geolocation.getCurrentPosition not triggering in iOS simulator with React Nativenavigator.geolocation.getCurrentPosition 没有在带有 React Native 的 iOS 模拟器中触发
【发布时间】:2018-10-29 16:38:27
【问题描述】:

在 Android 模拟器中,以下代码可以正常工作,但在 iOS 中,它甚至不会进入 navigator.geolocation.getCurrentPosition。

我已经通过调试菜单更新了我的模拟器的自定义位置,但如果它甚至没有进入 navigator.geolocation.getCurrentPosition 我有点迷茫。

constructor(props) {
    super(props);
    this.state = {
        focusedLocation: {
            latitude: 37.4219999,
            longitude: -122.0862462,
            latitudeDelta: 0.0022,
            longitudeDelta: Dimensions.get("window").width / Dimensions.get("window").height * 0.0122,
        },
    };
}    

componentDidMount() {

    console.log("did mount: ", this.state.grumblersLocation.latitude); //triggers iOS and Android

    navigator.geolocation.getCurrentPosition(pos => {
            console.log("raw pos lat: ", pos.coords.latitude); //triggers in Android only
            this.setState({
                focusedLocation: {
                    ...this.state.grumblersLocation,
                    latitude: pos.coords.latitude,
                    longitude: pos.coords.longitude
                }
            }, () => {
                console.log("state after pos lat: ", this.state.grumblersLocation.latitude);  //triggers in Android only
            });

        },
        err => {
            console.log("Fetching the Position failed: ", err); //Not triggering on either
        });

}

【问题讨论】:

    标签: react-native geolocation ios-simulator react-native-maps


    【解决方案1】:

    编辑:弹出窗口从未出现在 IOS 中,因为我将隐私消息信息添加到错误的 info.plist 文件中。它需要到这里:

    编辑:在 iOS 中对我有用的另一个修复是:

    1. 在模拟器上点击主页按钮
    2. 单击设置 app>隐私>定位服务>我的应用
    3. 然后确保“使用时 该应用程序”已检查

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2018-03-18
      • 2017-11-17
      • 2019-04-29
      • 1970-01-01
      • 2017-05-14
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多