React Native应用程序:无权使用位置服务

Ant*_*ang 5 geolocation google-maps-api-3 react-native

我目前正在开发一个使用手机地理定位服务的项目。我目前在使用这项服务时遇到问题,它说地理定位未获得授权。

我尝试在互联网上查找,有些人遇到了同样的问题,但我没有设法解决它......

  componentDidMount() {
    const { coordinate } = this.state;

    this.requestCameraPermission();

    this.watchID = navigator.geolocation.watchPosition(
      position => {
        const { routeCoordinates, distanceTravelled } = this.state;
        const { latitude, longitude } = position.coords;

        const newCoordinate = {
          latitude,
          longitude
        };
        console.log({ newCoordinate });

        coordinate.timing(newCoordinate).start();

        this.setState({
          latitude,
          longitude,
          routeCoordinates: routeCoordinates.concat([newCoordinate]),
          distanceTravelled:
            distanceTravelled + this.calcDistance(newCoordinate),
          prevLatLng: newCoordinate
        });
      },
      error => console.log(error),
      {
        enableHighAccuracy: true,
        timeout: 20000,
        maximumAge: 1000,
        distanceFilter: 10
      }
    );
  }

Run Code Online (Sandbox Code Playgroud)

我没有出现在当前位置,而是出现在旧金山(这是地图上的默认位置)。函数 navigator.geolocation.watchPosition 收到错误:“code”:“E_LOCATION_UNAUTHORIZED”,“message”:“未授权使用位置服务”,“watchId”:1,

我的手机是三星S9并且启用了定位服务...所以我真的很好奇我现在遇到的问题。

Ant*_*ang 3

谢谢您的回答,我设法解决了我的问题,显然由于某种原因世博会不允许使用我的位置,所以我只是强制它:

  Location.requestPermissionsAsync();
Run Code Online (Sandbox Code Playgroud)