zoukankan      html  css  js  c++  java
  • vue 里面引入高德地图

    效果图:

      

      实现:

        一:引入 高德,web-sdk (两种方式)

         1:在html 中引入(我用的这一种)

          <script type="text/javascript" src="http://webapi.amap.com/maps?v=1.4.6&key=你申请的高德appKey&plugin=AMap.Walking"></script>
         2:安装vue-amap
          
           文档地址:https://elemefe.github.io/vue-amap/#/zh-cn/introduction/install    按照文档自己来把,这里不多说了;
        二:调用 
          
          
          定义一个地图的展示区域叫 containner  里面那个panel 是展示规划路线用的,可自行看高德API了解下;
     
          

        上述就是实现代码,可打开下面粘贴

          

    let map = new AMap.Map('container', {
                        center: [this.tableData[0].longitude, this.tableData[0].latitude],
                        resizeEnable: true,
                        zoom: 30
                    });
                    AMap.plugin(['AMap.ToolBar', 'AMap.Scale'], function () {
                        map.addControl(new AMap.ToolBar())
                        map.addControl(new AMap.Scale())
                    });
                    //画一个车的位置
                    let marker = new AMap.Marker({
                        //icon: "http://webapi.amap.com/theme/v1.3/markers/n/mark_b.png",
                        icon:require("../assets/che.png"),
                        position: [this.tableData[0].longitude, this.tableData[0].latitude],
                        "40px",
                        height:"40px",
                    });
                    marker.setMap(map); 
                    //画附近所有站点的位置
                    console.log(res.data.data[1].longitude,res.data.data[1].latitude)
                    for (var index = 0; index < res.data.data.length; index++) {
                        let marker = new AMap.Marker({
                            //icon: "http://webapi.amap.com/theme/v1.3/markers/n/mark_r.png",
                            icon:require("../assets/p.png"),
                            position:[res.data.data[index].longitude,res.data.data[index].latitude],
                        });
                        marker.setMap(map); 
                    }
    View Code

        还有个规划路线的部分:

    var walking = new AMap.Walking({
                        map: map,
                        panel: "panel"
                    });
                    walking.search([this.tableData[0].longitude, this.tableData[0].latitude], [res.data.data[0].longitude,res.data.data[0].latitude]);
    View Code
  • 相关阅读:
    【校招面试 之 C/C++】第1题 为什么优先使用构造函数的初始化列表
    Linux平台ORACLE INSTANT客户端安装
    ORACLE数据库链接
    ORACLE用户管理
    【转】软件开发工具介绍之 6.Web开发工具
    【转】三大UML建模工具Visio、Rational Rose、PowerDesign的区别
    ORACLE数据库查看执行计划
    数据分析方法
    ORACLE对象大小写问题
    计算机改名引发的ORA
  • 原文地址:https://www.cnblogs.com/lijuntao/p/9111564.html
Copyright © 2011-2022 走看看