camera.ts 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. // pages/camera/camera.ts
  2. Page({
  3. /**
  4. * 页面的初始数据
  5. */
  6. data: {
  7. },
  8. /**
  9. * 生命周期函数--监听页面加载
  10. */
  11. onLoad() {
  12. },
  13. /**
  14. * 生命周期函数--监听页面初次渲染完成
  15. */
  16. onReady() {
  17. },
  18. /**
  19. * 生命周期函数--监听页面显示
  20. */
  21. async onShow() {
  22. const { authSetting } = await wx.getSetting();
  23. console.log('authSetting', authSetting['scope.userLocation'])
  24. if (authSetting['scope.userLocation']) {
  25. wx.getLocation({
  26. type: 'gcj02',
  27. isHighAccuracy:true,
  28. success(res) {
  29. const latitude = res.latitude
  30. const longitude = res.longitude
  31. const speed = res.speed
  32. const accuracy = res.accuracy
  33. console.log('第一次-getLocation', res)
  34. }
  35. })
  36. wx.startLocationUpdate({
  37. type:'gcj02',
  38. isHighAccuracy:true,
  39. altitude:true,
  40. highAccuracyExpireTime:4000,
  41. success:(res)=>{
  42. console.log('startLocationUpdate',res)
  43. }
  44. })
  45. wx.onLocationChange((res)=>{
  46. console.log('移动获取',res)
  47. })
  48. } else {
  49. wx.getLocation({
  50. type: 'wgs84',
  51. success(res) {
  52. const latitude = res.latitude
  53. const longitude = res.longitude
  54. const speed = res.speed
  55. const accuracy = res.accuracy
  56. console.log('res', res)
  57. }
  58. })
  59. }
  60. },
  61. /**
  62. * 生命周期函数--监听页面隐藏
  63. */
  64. onHide() {
  65. },
  66. /**
  67. * 生命周期函数--监听页面卸载
  68. */
  69. onUnload() {
  70. wx.offLocationChange()
  71. wx.stopLocationUpdate({
  72. success:(res)=>{
  73. console.log('stopLocationUpdate',res)
  74. }
  75. })
  76. },
  77. /**
  78. * 页面相关事件处理函数--监听用户下拉动作
  79. */
  80. onPullDownRefresh() {
  81. },
  82. /**
  83. * 页面上拉触底事件的处理函数
  84. */
  85. onReachBottom() {
  86. },
  87. /**
  88. * 用户点击右上角分享
  89. */
  90. onShareAppMessage() {
  91. },
  92. handleGetLocation(){
  93. wx.getLocation({
  94. type: 'gcj02',
  95. isHighAccuracy:true,
  96. altitude:true,
  97. success(res) {
  98. const latitude = res.latitude
  99. const longitude = res.longitude
  100. const speed = res.speed
  101. const accuracy = res.accuracy
  102. console.log('手动getLocation', res)
  103. wx.showModal({
  104. title: '提示',
  105. content: JSON.stringify(res),
  106. success (res) {
  107. if (res.confirm) {
  108. console.log('用户点击确定')
  109. } else if (res.cancel) {
  110. console.log('用户点击取消')
  111. }
  112. }
  113. })
  114. }
  115. })
  116. }
  117. })