uniapp+微信小步伐+地图+传入多个标记点显示+点击打开内置地图导航+完整代 ...

打印 上一主题 下一主题

主题 946|帖子 946|积分 2838

 一、结果展示


二、完整代码

  1. <template>
  2.         <view class="container">
  3.                 <map class="map-container" :latitude="latitude" :longitude="longitude"
  4.                         :markers="markers" :controls="controls" show-location
  5.                         @markertap="onMarkerTap">
  6.                 </map>
  7.         </view>
  8. </template>
  9. <script>
  10. export default {
  11.         data() {
  12.                 return {
  13.                         latitude: 34.341568, // 默认中心点(西安)
  14.                         longitude: 108.940174,
  15.                         // 标记点(多个位置)
  16.                         markers: [
  17.                                 {
  18.                                         id: 1,
  19.                                         latitude: 34.341568,
  20.                                         longitude: 108.940174,
  21.                                         title: "",
  22.                                         iconPath: "/static/location.png", // 标记点图标
  23.                                         width: 30,
  24.                                         height: 30,
  25.                                         callout: {
  26.                                                 content: "点击导航",
  27.                                                 color: "#ffffff",
  28.                                                 fontSize: 14,
  29.                                                 borderRadius: 10,
  30.                                                 bgColor: "#000000",
  31.                                                 padding: 8,
  32.                                                 display: "ALWAYS"
  33.                                         }
  34.                                 },
  35.                                 {
  36.                                         id: 2,
  37.                                         latitude: 34.250568,
  38.                                         longitude: 108.950174,
  39.                                         title: "",
  40.                                         iconPath: "/static/location.png",
  41.                                         width: 30,
  42.                                         height: 30,
  43.                                         callout: {
  44.                                                 content: "点击导航",
  45.                                                 color: "#ffffff",
  46.                                                 fontSize: 14,
  47.                                                 borderRadius: 10,
  48.                                                 bgColor: "#000000",
  49.                                                 padding: 8,
  50.                                                 display: "ALWAYS"
  51.                                         }
  52.                                 }
  53.                         ]
  54.                 };
  55.         },
  56.         methods: {
  57.                 // 点击标记点触发导航
  58.                 onMarkerTap(e) {
  59.                         const marker = this.markers.find(m => m.id === e.markerId);
  60.                         if (marker) {
  61.                                 uni.openLocation({
  62.                                         latitude: marker.latitude,
  63.                                         longitude: marker.longitude,
  64.                                         name: marker.title,
  65.                                         address: marker.title,
  66.                                         scale: 18
  67.                                 });
  68.                         }
  69.                 }
  70.         }
  71. };
  72. </script>
  73. <style>
  74. .container {
  75.         width: 100vw;
  76.         height: 100vh;
  77.         overflow: hidden;
  78. }
  79. .map-container {
  80.         width: 100%;
  81.         height: 100%;
  82.         position: absolute;
  83.         top: 0;
  84.         left: 0;
  85. }
  86. </style>
复制代码
三、代码表明 

   整体说一下就是map直接组件就显示地图,marker就是标记点传进来显示,uni.openLocation这个就是打开手机内置地图然后选择你的地图就能正常导航过去

免责声明:如果侵犯了您的权益,请联系站长,我们会及时删除侵权内容,谢谢合作!更多信息从访问主页:qidao123.com:ToB企服之家,中国第一个企服评测及商务社交产业平台。
回复

使用道具 举报

0 个回复

倒序浏览

快速回复

您需要登录后才可以回帖 登录 or 立即注册

本版积分规则

曹旭辉

金牌会员
这个人很懒什么都没写!
快速回复 返回顶部 返回列表