洛阳学员端
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

107 lines
5.3 KiB

7 months ago
7 months ago
7 months ago
3 months ago
7 months ago
7 months ago
7 months ago
7 months ago
7 months ago
7 months ago
7 months ago
  1. var KJTencentLocation = uni.requireNativePlugin("KJ-TencentLocation");
  2. var kic = {
  3. "apiKey": "JTOBZ-KLLKQ-S325W-25JZC-JLHEV-WNF5J", //ios才有效,andorid的在App原生插件配置里设置BPMBZ-VSKE3-MC23F-O3KZO-AZGI7-PXFJI
  4. "deviceID": "oaid" //andorid必须设置,默认使用oaid,ios无需设置
  5. }
  6. // 获取系统信息
  7. const systemInfo = uni.getSystemInfoSync();
  8. if (systemInfo.platform === 'ios') { // 如果是 iOS 平台
  9. KJTencentLocation.setUserAgreePrivacy({"isAgree": true});
  10. KJTencentLocation.getLocationAuthorizationStatus((res) => {
  11. console.log("getLocationAuthorizationStatus:" + JSON.stringify(res));
  12. /**
  13. * status - 权限状态 0-还没决定 1-受限制 2-拒绝 345-已授权
  14. * */
  15. });
  16. KJTencentLocation.requestLocationAuthorization((res) => {
  17. console.log("requestLocationAuthorization:" + JSON.stringify(res));
  18. /**
  19. * status - 权限状态 0-还没决定 1-受限制 2-拒绝 345-已授权
  20. * */
  21. });
  22. delete kic.deviceID
  23. }
  24. KJTencentLocation.init(kic);
  25. var dic = {
  26. "coordinateType": "GCJ02", //设置坐标系 GCJ02(火星坐标,即国测局坐标) WGS84(地球坐标,注:如果是海外,无论设置的是火星坐标还是地球坐标,返回的都是地球坐标)
  27. "requestLevel": 4, //请求等级 0(包含经纬度) 1(包含经纬度, 位置名称, 位置地址) 3(包含经纬度,位置所处的中国大陆行政区划) 4(包含经纬度,位置所处的中国大陆行政区划及周边POI列表)
  28. /**以下andorid有效**/
  29. "mockEnable": false, //是否允许mockGps数据 设置为true后将不对mockGps进行过滤,是否允许应用对GPS进行模拟
  30. "systemCacheEnable": false, //是否允许在定位失败情况下返回系统缓存位置
  31. //"deviceID":"xxx", //设备id
  32. "userAgreePrivacy": true, //设置用户是否同意隐私协议政策
  33. "allowCache": true, //是否允许使用缓存
  34. "allowDirection": true, //是否允许使用设备传感器获取方向
  35. "allowGPS": true, //是否允许使用GPS进行定位
  36. "gnssSource": 20, //设置优先卫星定位信号来源 改设置仅对连续定位生效,20(GPS) 21(北斗)
  37. "gpsFirst": false, //首次定位是否等待卫星定位结果,默认为false 当设置为true时,首次定位会等待卫星定位结果,默认等待时间为30s,超时将返回网络定位结果
  38. "gpsFirstTimeOut": 10000, //卫星定位优先时,等待卫星定位结果对的超时时间,单位: ms, 最多等待60s.
  39. "indoorLocationMode": true, //启动室内定位
  40. "interval": 5000, //定位周期(位置监听器回调周期), 单位为 ms (毫秒).
  41. "locMode": 10, //定位模式 10(高精度定位模式,将同时使用网络定位和卫星定位,优先返回精度高的定位) 11(仅网络定位模式,将不启动gps定位,只使用网络定位,可以减少耗电量,但定位精度有所降低) 12(仅GPS定位模式)
  42. // "phoneNumber": "111",
  43. // "qq": "xxx",
  44. // "smallAppKey": "xxx", //设置分渠道的key编码号,例如小程序里面区分业务.
  45. /**以下ios有效**/
  46. "distanceFilter": 0, //设置定位的最小更新距离
  47. "desiredAccuracy": "best", //设置定位精度 bestForNavigation best nearestTenMeters hundredMeters kilometer threeKilometers
  48. "pausesLocationUpdatesAutomatically": false, //定设置位是否会被系统自动暂停
  49. "allowsBackgroundLocationUpdates": true, //设置是否允许后台定位 为true 需要配置manifest.json->App常用其它设置->后台运行能力 location
  50. "activityType": 1, //设置用户的活动类型 1(未知的出行活动类型) 2(位置管理器专门为出行活动为汽车的时候导航) 3(位置管理器专门为步行、跑步、骑自行车等健身时,提供导航) 4(位置管理器专门为其他类型的大型交通工具导航,而不是汽车导航)
  51. //"headingFilter": 10, //设置当朝向改变时,每隔多少度调用一次
  52. "headingOrientation": 0, //设置设备当前的朝向 0(未知) 1(竖屏) 2(竖屏正方向,颠倒) 3(屏左方向,主按钮在右侧) 4(横屏右方向,主按钮在左侧) 5(设备正面朝上) 6(设备正面朝下)
  53. "poiUpdateInterval": 10, //指定POI的更新间隔 单位秒
  54. "enableAntiMockLocation": true //是否允许开启反作弊检查
  55. }
  56. KJTencentLocation.setLocationManagerInfo(dic)
  57. export function requestSingleFreshLocation() {
  58. return new Promise((resolve, reject) => {
  59. console.log(KJTencentLocation.requestSingleFreshLocation)
  60. KJTencentLocation.requestSingleFreshLocation((res) => {
  61. console.log(res)
  62. if (systemInfo.platform === 'ios') { // 如果是 iOS 平台
  63. if (res.location.fakeCode != 0) {
  64. uni.$u.toast('请关闭虚拟定位')
  65. let obj = {
  66. location: {
  67. latitude: '',
  68. longitude: '',
  69. city: '虚拟定位'
  70. }
  71. }
  72. resolve(obj)
  73. }
  74. }
  75. // if(res.location.latitude==0) {
  76. // uni.showModal({
  77. // title: 'app想要获取您的定位权限',
  78. // content: '为了能够获取精确的数据,请去手机设置里手动开启app定位权限',
  79. // showCancel: false,
  80. // confirmText: '知道了,关闭弹窗',
  81. // success: function (res) {
  82. // if (res.confirm) {
  83. // console.log('用户点击确定');
  84. // } else if (res.cancel) {
  85. // console.log('用户点击取消');
  86. // }
  87. // }
  88. // });
  89. // }
  90. resolve(res)
  91. });
  92. })
  93. }