parkingLists.vue 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. <template>
  2. <view>
  3. <map
  4. id="pagemap"
  5. style="width: 100%; height: 100vh;"
  6. :show-location="true"
  7. :latitude="latitude"
  8. :longitude="longitude"
  9. @markertap="markertap"
  10. :markers="covers"></map>
  11. <!-- <u-empty src="/static/img/empty.png" icon-size="335" text="正在建设中" color="#878787" mode="search"></u-empty> -->
  12. <u-toast ref="uToast" />
  13. </view>
  14. </template>
  15. <script>
  16. export default{
  17. data(){
  18. return{
  19. page_map:'',
  20. id: 0, //使用 marker点击事件 需要填写id
  21. latitude: 26.64969,
  22. longitude: 106.636453,
  23. covers: [{
  24. latitude: 26.597864,
  25. longitude: 106.72947,
  26. iconPath: 'https://www.baidu.com/img/flexible/logo/pc/result.png'
  27. }],
  28. }
  29. },
  30. onLoad(){
  31. this.page_map = uni.createMapContext("pagemap",this);
  32. // console.log('page_map',this.page_map);
  33. this.getNearRoadsl();
  34. },
  35. onShow() {
  36. this.getLocation();
  37. },
  38. methods:{
  39. getLocation(){
  40. let that = this;
  41. // console.log("请求定位")
  42. uni.getLocation({
  43. type:"gcj02",
  44. success : function (res) {
  45. // console.log("定位返回信息:", res);
  46. that.latitude = res.latitude;
  47. that.longitude = res.longitude;
  48. // console.log('that.latitude',that.latitude)
  49. // console.log(res.longitude + "," + res.latitude )
  50. },
  51. fail: function(res){
  52. console.log("请求错误:", res)
  53. }
  54. })
  55. },
  56. async getNearRoadsl(){
  57. await this.getLocation();
  58. this.$u.api.nearRoadsl({latitude:this.latitude,longitude:this.longitude})
  59. .then(res=>{
  60. // this.$refs.uToast.show({
  61. // title: res.msg,
  62. // type: 'success',
  63. // });
  64. // this.covers = res.data;
  65. // console.log('this.covers',this.covers)
  66. res.data.forEach(item=>{
  67. if(item.latitude&&item.longitude){
  68. let marker = {
  69. latitude: item.latitude,
  70. longitude:item.longitude,
  71. // id:'0',
  72. iconPath: 'https://www.baidu.com/img/flexible/logo/pc/result.png'
  73. }
  74. this.covers.push(marker);
  75. }
  76. })
  77. // this.covers =
  78. // console.log('getNearRoadsl',res)
  79. }).catch(err=>{
  80. this.$refs.uToast.show({
  81. title: err.msg,
  82. type: 'error',
  83. });
  84. console.log('getNearRoadsl ',err)
  85. });
  86. },
  87. markertap(e){
  88. console.log('markertap',e)
  89. }
  90. }
  91. }
  92. </script>
  93. <style lang="scss" scoped>
  94. .wrap{margin-top: 20vh;}
  95. @import url("./parkingLists.scss");
  96. </style>