当前位置:   article > 正文

vue 百度地图获取经纬度地址_vue 百度地图 标注 获取 经纬度

vue 百度地图 标注 获取 经纬度

地图安装看这个https://blog.csdn.net/Iphone886/article/details/127976856?ops_request_misc=&request_id=&biz_id=102&utm_term=vue2%E7%99%BE%E5%BA%A6%E5%9C%B0%E5%9B%BE%E4%BD%BF%E7%94%A8&utm_medium=distribute.pc_search_result.none-task-blog-2~all~sobaiduweb~default-1-127976856.142^v68^control,201^v4^add_ask,213^v2^t3_esquery_v1&spm=1018.2226.3001.4187

1,搜索任意地址

2,弹出经,纬度,地址。

 3,保存后。F12,打印出经,纬度地址。

 

 4,点击地图任意点。查出经,纬度,地址。

上代码。

index.vue

  1. <template>
  2. <el-container>
  3. <el-dialog width="60%" :visible.sync="mapVisible" append-to-body>
  4. <baidu-map style="display:flex;flex-direction: column-reverse;" class="bm-view" @ready="mapReady"
  5. @click="getLocation" :scroll-wheel-zoom="true">
  6. <bm-navigation anchor="BMAP_ANCHOR_TOP_RIGHT"></bm-navigation>
  7. <bm-marker v-if="infoWindowShow" :position="{lng: form.lng, lat: form.lat}">
  8. </bm-marker>
  9. <bm-info-window :position="{lng: form.lng, lat: form.lat}" :show="infoWindowShow"
  10. @clickclose="infoWindowClose">
  11. <p>当前位置:{{form.address}}</p>
  12. <p>经度:{{form.lng}}</p>
  13. <p>纬度:{{form.lat}}</p>
  14. </bm-info-window>
  15. <div style="margin-bottom: 10px;">
  16. <bm-auto-complete v-model="form.address" :sugStyle="{zIndex: 999999}">
  17. <el-input v-model="form.address" style="width:300px;margin-right:15px" placeholder="输入地址"
  18. clearable></el-input>
  19. </bm-auto-complete>
  20. <el-button type="primary" @click="getBaiduMapPoint">搜索</el-button>
  21. <el-button type="primary" @click="closeMap()">保存</el-button>
  22. </div>
  23. </baidu-map>
  24. </el-dialog>
  25. </el-container>
  26. </template>
  27. <script>
  28. export default {
  29. data() {
  30. return {
  31. lng: "", //经度
  32. lat: "", //纬度
  33. address: "", //详细地址
  34. infoWindowShow: false, //地图详细地址显示
  35. mapVisible: false, //百度地图弹框
  36. }
  37. </script>
  38. methods: {
  39. //百度地图初始化
  40. mapReady({
  41. BMap,
  42. map
  43. }) {
  44. // 默认经纬度作为中心点
  45. this.point = new BMap.Point(116.393541, 39.902292);
  46. map.centerAndZoom(this.point, 15);
  47. this.BMap = BMap
  48. this.map = map
  49. },
  50. //点击获取经纬度
  51. getLocation(e) {
  52. this.form.lng = e.point.lng //经度
  53. this.form.lat = e.point.lat //纬度
  54. console.log(e.point.lng)
  55. console.log(e.point.lat)
  56. var point = new BMap.Point(e.point.lng, e.point.lat);
  57. var gc = new BMap.Geocoder();
  58. let _this = this;
  59. gc.getLocation(point, function(rs) {
  60. //地址信息
  61. _this.form.address = rs.address;
  62. });
  63. this.infoWindowShow = true
  64. },
  65. getBaiduMapPoint() {
  66. let that = this
  67. let myGeo = new this.BMap.Geocoder()
  68. myGeo.getPoint(this.form.address, function(point) {
  69. if (point.lng != '116.413384') {
  70. that.map.centerAndZoom(point, 15)
  71. that.form.lng = point.lng //经度
  72. that.form.lat = point.lat //纬度
  73. that.infoWindowShow = true
  74. } else {
  75. that.$message({
  76. message: "请选择正确地址!!!",
  77. type: "warning",
  78. });
  79. this.infoWindowShow = false
  80. }
  81. })
  82. },
  83. //百度地图信息窗口关闭
  84. infoWindowClose() {
  85. this.form.lng = ""; //经度
  86. this.form.lat = ""; //纬度
  87. this.form.address = ""; //详细地址
  88. this.infoWindowShow = false;
  89. },
  90. //弹出百度地图
  91. addMap() {
  92. this.infoWindowShow = false;
  93. this.mapVisible = true;
  94. },
  95. //关闭地图
  96. closeMap() {
  97. console.log(this.form.lng);
  98. console.log(this.form.lat);
  99. console.log(this.form.address);
  100. this.mapVisible = false; //关闭弹窗
  101. },
  102. }

有问题,请留言。

或2297660550@qq.com联系我

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/你好赵伟/article/detail/109791
推荐阅读
相关标签
  

闽ICP备14008679号