• uniapp+地图 实现目的地导航


    uniapp小程序实现导航功能,以下是效果图

    代码标注如图所示,配置的话,请参考上一篇文章uniapp+腾讯地图定位获取位置信息

    代码附上

    1. <template>
    2. <view>
    3. <view class="map-container">
    4. <map :longitude="longitude" :latitude="latitude" :scale="scale" @markertap="showLocationInfo" class="map"
    5. :markers="markers">
    6. </map>
    7. </view>
    8. </view>
    9. </template>
    10. <script setup>
    11. import {
    12. ref,
    13. onMounted
    14. } from "vue";
    15. const longitude = ref(104.065867) // 经度
    16. const latitude = ref(30.657627) // 纬度
    17. const scale = ref(10) // 缩放级别
    18. const markers = ref([{
    19. id: 1,
    20. longitude: 104.049391,
    21. latitude: 30.683977,
    22. title: '花牌坊',
    23. iconPath: '../../static/images/1-1.jpg',
    24. address: '花牌坊地铁口A口',
    25. width: 30,
    26. height: 30
    27. },
    28. {
    29. id: 2,
    30. longitude: 104.042178,
    31. latitude: 30.639979,
    32. title: '高升桥',
    33. iconPath: '../../static/images/1-2.jpg',
    34. address: '高升桥地铁口A口',
    35. width: 30,
    36. height: 30
    37. },
    38. ])
    39. const showInfo = ref(false)
    40. const showLocationInfo = (e) => {
    41. console.log(e);
    42. const markerId = e.markerId
    43. const clickedMarker = markers.value.find((item) => item.id === markerId);
    44. uni.openLocation({
    45. latitude: parseFloat(clickedMarker.latitude), // 要去的地址经度,浮点数
    46. longitude: parseFloat(clickedMarker.longitude), // 要去的地址纬度,浮点数
    47. name: clickedMarker.title, // 位置名
    48. address: clickedMarker.address, // 要去的地址详情说明
    49. scale: 16, // 地图缩放级别,整形值,范围从1~28。默认为最大
    50. });
    51. // 拼接腾讯地图的 URL Scheme,传递经度、纬度、位置名和地址等参数
    52. const url = `http://map/routeplan?type=drive&to={{clickedMarker.title}}&tocoord=30.683977,104.049391`;
    53. // 使用 wx.openDocument 打开 URL,自动跳转到腾讯地图软件
    54. uni.openDocument({
    55. filePath: url,
    56. });
    57. };
    58. onMounted(() => {
    59. const mapCtx = uni.createMapContext('myMap');
    60. console.log(mapCtx); // 可在此处使用 mapCtx 进行其他操作
    61. });
    62. </script>
    63. <style>
    64. .map {
    65. width: 100%;
    66. height: 200px;
    67. }
    68. </style>

    希望可以有帮助

  • 相关阅读:
    【目标检测】Visdrone数据集和CARPK数据集预处理
    【HBZ分享】云数据库如何定位慢查询
    C进阶---自定义类型:结构体、枚举、联合
    logging日志及其使用代码
    Baklib知识分享|企业产品需求文档的特点
    MongoDB中的分布式集群架构
    2016 ZCTF note3:一种新解法
    【车载测试收徒】【UDS诊断中的协议:ISO-14229中文】
    2、计算机图形学——视图变换
    @Async可以和@Transactional结合使用吗?
  • 原文地址:https://blog.csdn.net/m0_64931981/article/details/132634677