h5-测试获取位置.vue 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. <template>
  2. <view>
  3. <!-- <web-view :src="href"></web-view> -->
  4. {{res}}
  5. </view>
  6. </template>
  7. <script>
  8. export default {
  9. data() {
  10. return {
  11. href: "",
  12. res:""
  13. };
  14. },
  15. onLoad(option) {
  16. // #ifndef APP-NVUE
  17. const eventChannel = this.getOpenerEventChannel();
  18. // #endif
  19. // 监听acceptDataFromOpenerPage事件,获取上一页面通过eventChannel传送到当前页面的数据
  20. eventChannel.on('acceptDataFromOpenerPage', (data) => {
  21. uni.setNavigationBarTitle({
  22. title: data.title
  23. })
  24. let url = escape(data.url)
  25. let title = escape(data.title)
  26. // 获取位置
  27. uni.getLocation({
  28. type: 'gcj02',
  29. geocode: true ,
  30. success: (res)=> {
  31. this.res = res
  32. console.log(res)
  33. console.log('当前位置的经度:' + res.longitude);
  34. console.log('当前位置的纬度:' + res.latitude);
  35. }
  36. });
  37. // this.href = "http://oa_system.nxmy.com:8011/oa_login?staff_num=" + uni.getStorageSync('user')
  38. // .staff_num + "&url=" + url + "&title=" + title
  39. })
  40. }
  41. }
  42. </script>
  43. <style lang="scss">
  44. </style>