camera.ts 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  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: 'wgs84',
  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:'wgs84',
  38. isHighAccuracy:true,
  39. highAccuracyExpireTime:4000,
  40. success:(res)=>{
  41. console.log('startLocationUpdate',res)
  42. }
  43. })
  44. wx.onLocationChange((res)=>{
  45. console.log('移动获取',res)
  46. })
  47. } else {
  48. wx.getLocation({
  49. type: 'wgs84',
  50. success(res) {
  51. const latitude = res.latitude
  52. const longitude = res.longitude
  53. const speed = res.speed
  54. const accuracy = res.accuracy
  55. console.log('res', res)
  56. }
  57. })
  58. }
  59. },
  60. /**
  61. * 生命周期函数--监听页面隐藏
  62. */
  63. onHide() {
  64. },
  65. /**
  66. * 生命周期函数--监听页面卸载
  67. */
  68. onUnload() {
  69. wx.offLocationChange()
  70. wx.stopLocationUpdate({
  71. success:(res)=>{
  72. console.log('stopLocationUpdate',res)
  73. }
  74. })
  75. },
  76. /**
  77. * 页面相关事件处理函数--监听用户下拉动作
  78. */
  79. onPullDownRefresh() {
  80. },
  81. /**
  82. * 页面上拉触底事件的处理函数
  83. */
  84. onReachBottom() {
  85. },
  86. /**
  87. * 用户点击右上角分享
  88. */
  89. onShareAppMessage() {
  90. },
  91. handleGetLocation(){
  92. wx.getLocation({
  93. type: 'wgs84',
  94. isHighAccuracy:true,
  95. success(res) {
  96. const latitude = res.latitude
  97. const longitude = res.longitude
  98. const speed = res.speed
  99. const accuracy = res.accuracy
  100. console.log('手动getLocation', res)
  101. wx.showModal({
  102. title: '提示',
  103. content: JSON.stringify(res),
  104. success (res) {
  105. if (res.confirm) {
  106. console.log('用户点击确定')
  107. } else if (res.cancel) {
  108. console.log('用户点击取消')
  109. }
  110. }
  111. })
  112. }
  113. })
  114. }
  115. })