【问题标题】:navigator.geolocation.getCurrentPosition is not working in React Native Version(0.60) and above, How to fetch location?navigator.geolocation.getCurrentPosition 在 React Native 版本(0.60)及更高版本中不起作用,如何获取位置?
【发布时间】:2019-07-24 14:24:09
【问题描述】:

尝试使用geoLocation获取当前位置,它在React Native版本(0.60)及更高版本中不起作用,但它在以下版本中起作用

我意识到,GeoLocation 文件夹不在 nodeModules/React-Native/Libraries 中, 他们是否将其从 ReactNative(0.60) 中删除?

        navigator.geolocation.getCurrentPosition((position) => {
        console.log(position)
    },
    (error) => alert(JSON.stringify(error)),)

收到此错误:

类型错误:未定义不是对象(评估 'navigator.geolocation.getCurrentPosition

【问题讨论】:

标签: react-native geolocation


【解决方案1】:

似乎 geolocation 已从 react native .60 版本中删除。

试试这个:

npm install @react-native-community/geolocation --save

react-native link @react-native-community/geolocation

您可以查看related SO post了解更多详情。

【讨论】:

    【解决方案2】:

    npm install @react-native-community/geolocation --save

    react-native 链接@react-native-community/geolocation

    然后:

    import Geolocation form '@react-native-community/geolocation';
    Geolocation.etCurrentPosition((position) => {
        console.log(position)
    },
    (error) => alert(JSON.stringify(error))
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-05-18
      • 1970-01-01
      • 2014-05-07
      • 2018-09-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多