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.

64 lines
1.4 KiB

8 months ago
  1. <template>
  2. <view class="map">
  3. <view class="page-body">
  4. <view class="page-section page-section-gap">
  5. <map style="width: 100%; height: 300px;" :latitude="latitude" :longitude="longitude" :markers="covers"></map>
  6. </view>
  7. </view>
  8. </view>
  9. </template>
  10. <script>
  11. export default {
  12. name: 'Map',
  13. data() {
  14. return {
  15. id: 0, // 使用 marker点击事件 需要填写id
  16. latitude: 0, //纬度
  17. longitude: 0, //经度
  18. covers: [{
  19. latitude: 0,
  20. longitude: 0,
  21. iconPath: '../../static/map/location.png'
  22. }]
  23. }
  24. },
  25. onShow() {
  26. let _self = this;
  27. //获取用户当前位置
  28. uni.getLocation({
  29. type: 'gcj02', // 'wgs84'默认gps 坐标 'gcj02'国测
  30. accuracy: 'best', // 精度值为20m
  31. geocode: true,
  32. isHighAccuracy : true,
  33. success: function (res) {
  34. _self.longitude = res.longitude
  35. _self.latitude = res.latitude
  36. _self.covers[0].longitude = res.longitude
  37. _self.covers[0].latitude = res.latitude
  38. }
  39. });
  40. uni.chooseLocation({
  41. complete(res){ //成功或失败都会调
  42. console.log(res);
  43. },
  44. success: function(res) { //成功回调
  45. uni.navigateTo({
  46. url: `/pages/mine/address?addressInfo=${JSON.stringify(res)}`
  47. })
  48. },
  49. fail : function(res){
  50. //定位获取失败或用户点击取消按钮触发
  51. uni.navigateTo({
  52. url: '/pages/mine/address'
  53. })
  54. }
  55. });
  56. }
  57. }
  58. </script>
  59. <style lang="scss" scoped>
  60. </style>