React-native 通过react-native-location库如何实现定位【附代码】

今天爱分享给大家带来React-native 通过react-native-location库如何实现定位【附代码】,希望能够帮助到大家。

(1).下载库到本地

npm install  react-native-location

(2).自动配置library

react-native link react-native-location

(3).如果是android系统需要权限

   
   

(4).示例

import RNLocation from 'react-native-location';

RNLocation.configure({
  distanceFilter: 5.0
})

RNLocation.requestPermission({
  ios: "whenInUse",
  android: {
    detail: "coarse"
  }
}).then(granted => {
    if (granted) {
      this.locationSubscription = RNLocation.subscribeToLocationUpdates(locations => {
        /* Example location returned
        {
          speed: -1,
          longitude: -0.1337,
          latitude: 51.50998,
          accuracy: 5,
          heading: -1,
          altitude: 0,
          altitudeAccuracy: -1
          floor: 0
          timestamp: 1446007304457.029
        }
        */
      })
    }
  })

原文链接:https://blog.itblood.com/977.html,转载请注明出处。
0
特工17 V0.25.9 官方中文版[更新][PC+安卓][4.6G] [亚洲风SLG/中文/动态CG]
特工17 V0.25.9 官方中文版[更新][PC+安卓][4.6G] [亚洲风SLG/中文/动态CG]
5分钟前 有人购买 去瞅瞅看

站点公告

显示验证码
没有账号?注册  忘记密码?