register_map.vue 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. <template>
  2. <view>
  3. <map id="myMap" style="width: 750rpx;height: 80vh;" :markers="markers" :longitude="longitude" :latitude="latitude"
  4. @tap="onTap">
  5. </map>
  6. <view class="">
  7. 请双击定位<br>
  8. {{addressData.address}}
  9. </view>
  10. </view>
  11. </template>
  12. <script>
  13. export default {
  14. data() {
  15. return {
  16. markers: [], //标记点
  17. latitude: 0,
  18. longitude: 0,
  19. createMap: "",
  20. touch: false,
  21. addressData:''
  22. };
  23. },
  24. onNavigationBarButtonTap(e) {
  25. if (e.index == 0) {
  26. this.inBack()
  27. }
  28. },
  29. created() {
  30. let that = this
  31. uni.getLocation({
  32. type: 'gcj02',
  33. geocode: true,
  34. success(res) {
  35. that.latitude = res.latitude
  36. that.longitude = res.longitude
  37. let point = new plus.maps.Point(that.longitude, that.latitude);
  38. plus.maps.Map.reverseGeocode(
  39. point, {},
  40. function(event) {
  41. that.addressData= event;
  42. },
  43. function(e) {}
  44. );
  45. that.markers = [{
  46. id: 1,
  47. latitude: res.latitude,
  48. longitude: res.longitude,
  49. iconPath: '/static/sailun/gps-icon.png',
  50. }]
  51. }
  52. });
  53. },
  54. onReady() {
  55. this.createMap = uni.createMapContext('myMap', this);
  56. },
  57. methods: {
  58. inBack() {
  59. uni.$emit("addressData", this.addressData)
  60. uni.navigateBack({})
  61. },
  62. onTap(e) {
  63. console.log(e)
  64. if (e.type == 'click') {
  65. let that = this;
  66. this.createMap.getCenterLocation({
  67. success(res) {
  68. console.log(res)
  69. that.latitude = res.latitude
  70. that.longitude = res.longitude
  71. that.markers = [{
  72. id: 1,
  73. latitude: that.latitude,
  74. longitude: that.longitude,
  75. iconPath: '/static/sailun/gps-icon.png',
  76. }]
  77. let point = new plus.maps.Point(res.longitude, res.latitude);
  78. plus.maps.Map.reverseGeocode(
  79. point, {},
  80. function(event) {
  81. that.addressData= event;
  82. },
  83. function(e) {}
  84. );
  85. }
  86. })
  87. }
  88. },
  89. },
  90. }
  91. </script>
  92. <style lang="scss">
  93. </style>