权限被拒绝 - React Native中的地理位置 [英] Permission denied - geolocation in React Native

查看:1483
本文介绍了权限被拒绝 - React Native中的地理位置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在使用React Native,获取自定义位置以及设置NSLocationWhenInUseUsageDescription密钥。在ios模拟器上运行的错误是这样的:

I've been playing around with React Native, getting custom locations to work and setting the "NSLocationWhenInUseUsageDescription" key. The error, when running on the ios simulator, is this:

{
 "code": 2,
 "message": "Unable to retrieve location.",
 "PERMISSION_DENIED": 1,
 "POSITION_UNAVAILABLE": 2,
 "TIMEOUT": 3 
}

这就是我从Geolocation示例页面直接获得的信息 https://facebook.github.io/react-native/docs/geolocation.html

This is what I have, pretty much straight from the Geolocation example page https://facebook.github.io/react-native/docs/geolocation.html

/* eslint no-console: 0 */
'use strict';

var React = require('react');
var ReactNative = require('react-native');
var {
  StyleSheet,
  Text,
  View,
} = ReactNative;

export default class GeolocationExample extends React.Component {
  state = {
    initialPosition: 'unknown'
  };

  componentDidMount() {
    navigator.geolocation.getCurrentPosition(
      (position) => {
        var initialPosition = JSON.stringify(position);
        this.setState({initialPosition});
      },
      (error) => alert(JSON.stringify(error)),
      {enableHighAccuracy: true, timeout: 20000, maximumAge: 1000}
    );
  }

  render() {
    return (
      <View>
        <Text>
          <Text style={styles.title}>Initial position: </Text>
          {this.state.initialPosition}
        </Text>
      </View>
    );
  }
}

var styles = StyleSheet.create({
  title: {
    fontWeight: '500',
  },
});

任何帮助将不胜感激!

Any help would be appreciated!

推荐答案

您需要在模拟器中设置位置。在模拟器菜单中有一个选项,如此问题中所述:在iPhone中设置位置模拟器

You need to set the location in the Simulator. There is an option for that in simulator menus as described in this question: Set the location in iPhone Simulator

这篇关于权限被拒绝 - React Native中的地理位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆