无法访问Android设备中的位置访问被拒绝,错误代码3,无位置提供程序可用

问题描述

我正在尝试访问位置。 我都尝试过 https://www.npmjs.com/package/react-native-geolocation-servicehttps://www.npmjs.com/package/@react-native-community/geolocation

如何解决?设置有问题吗?还是我的代码有问题?尽管我进行了很多搜索,并经历了所有无济于事的解决方案。 即使在此版本中启用了自动链接,也尝试了手动链接。但是无法解决问题。 还有其他模块可以获取位置吗?

我在AndroidManifest.xml中添加了以下几行

<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />

我的React配置

react-native-cli: 2.0.1
react-native: 0.62.2

反应本地社区/地理位置:^ 2.0.2

如果我在手机中手动打开位置信息,它将获取位置信息。并能够在android模拟器中获取位置。

import React,{ Component } from 'react';
import { View,PermissionsAndroid } from 'react-native';
import {
    withTheme,Appbar,} from 'react-native-paper';
import Geolocation from '@react-native-community/geolocation';
// import Geolocation from 'react-native-geolocation-service';
import RNAndroidLocationEnabler from 'react-native-android-location-enabler';

class AddBill extends Component {
    state = {
        initialposition: [],latitude: '',logitude: '',}

    async componentDidMount() {
        let granted = await PermissionsAndroid.request(
            PermissionsAndroid.PERMISSIONS.ACCESS_FINE_LOCATION
        );
        if (granted === PermissionsAndroid.RESULTS.GRANTED) {
            console.log("test")
            let config = {
                authorizationLevel: "auto"
            }
            Geolocation.setRNConfiguration(config);
            Geolocation.getCurrentPosition(
                (position) => {
                    console.log(position);
                },(error) => {
                    console.log(error);
                },{ enableHighAccuracy: true,timeout: 15000,maximumAge: 110000 }
            );
        } else {
            console.log('Location permission not granted!!!!');
        }
    };

    _back = () => {
        this.props.navigation.goBack()
    }

    render() {

        return (
            <>
                <Appbar.Header>
                    <Appbar.BackAction onPress={this._back} />
                    <Appbar.Content title="New Bill" />
                </Appbar.Header>
                <View></View>
            </>
        );
    }
}

export default withTheme(AddBill);

enter image description here

react-native-geolocation-service:^ 5.0.0

手动开启位置信息后出现相同错误

enter image description here

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)