【问题标题】:React Native - Accurate Current location(Latitude, Longitude)React Native - 准确的当前位置(纬度,经度)
【发布时间】:2018-08-27 15:07:38
【问题描述】:

您好,我正在使用以下代码来获取准确的当前纬度和经度 但我无法获得准确的位置,所以任何人都可以建议我如何在 react native(Android 和 iOS)中获得准确的当前纬度和经度。

this.watchID = navigator.geolocation.getCurrentPosition(
     (position) => {
       console.log(position);
       this.setState({
         latitude: position.coords.latitude,
         longitude: position.coords.longitude,
         error: null,
       });
     },
     (error) => this.setState({ error: error.message }),
     // { enableHighAccuracy: true, timeout: 20000, maximumAge: 1000 },
   );
 }

提前致谢。

【问题讨论】:

    标签: android ios reactjs react-native native


    【解决方案1】:

    要在 android manifest 中获得准确的位置和经度,您可以声明

    AndroidManifes.xml

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

    【讨论】:

      【解决方案2】:

      试试这个库react-native-geolocation-service

      希望对您有所帮助!

      【讨论】:

        猜你喜欢
        • 2013-08-03
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多