• 高德地图实现gps轨迹坐标定位代码


     

    1. <script>
    2. import {pxToRem} from '@/utils/rem.js';
    3. const pathList = [
    4. {
    5. path: [120.99152, 27.937717],
    6. msg: '2023-12-14 14:21:43'
    7. },
    8. {
    9. path: [120.99152, 27.937717],
    10. msg: '2023-12-14 14:21:43'
    11. },
    12. {
    13. path: [120.99152, 27.937717],
    14. msg: '2023-12-14 14:21:43'
    15. },
    16. {
    17. path: [120.99152, 27.937717],
    18. msg: '2023-12-14 14:21:43'
    19. },
    20. {
    21. path: [119.654841, 26.345312],
    22. msg: '2023-12-14 14:21:43'
    23. },
    24. {
    25. path: [119.604823, 26.146219],
    26. msg: '2023-12-14 14:21:43'
    27. },
    28. {
    29. path: [119.608848, 25.888029],
    30. msg: '2023-12-14 14:21:43'
    31. },
    32. {
    33. path: [119.604823, 25.719924],
    34. msg: '2023-12-14 14:21:43'
    35. },
    36. {
    37. path: [119.700834, 25.637084],
    38. msg: '2023-12-14 14:21:43'
    39. },
    40. {
    41. path: [119.750277, 25.506716],
    42. msg: '2023-12-14 14:21:43'
    43. },
    44. {
    45. path: [120.07108, 25.189062],
    46. msg: '2023-12-14 14:21:43'
    47. },
    48. {
    49. path: [120.374635, 24.832797],
    50. msg: '2023-12-14 14:21:43'
    51. },
    52. {
    53. path: [120.627598, 24.087605],
    54. msg: '2023-12-14 14:21:43'
    55. },
    56. {
    57. path: [120.406831, 22.596914],
    58. msg: '2023-12-14 14:21:43'
    59. },
    60. {
    61. path: [120.866763, 22.267658],
    62. msg: '2023-12-14 14:21:43'
    63. }
    64. ];
    65. export default {
    66. name: 'amapFence',
    67. data () {
    68. return {
    69. pxToRem,
    70. path: [], // 当前绘制的多边形经纬度数组
    71. polygonItem: [], // 地图上绘制的所有多边形对象
    72. polyEditors: [] // 所有编辑对象数组
    73. };
    74. },
    75. props: {
    76. paths: {} // 编辑
    77. },
    78. mounted () {
    79. this.intAmap(() => {});
    80. },
    81. methods: {
    82. // 绘制路线,
    83. drawPath (path) {
    84. const polyline1 = new AMap.Polyline({
    85. path, // 设置线覆盖物路径
    86. showDir: true,
    87. strokeColor: '#58aaff', // 线颜色
    88. strokeWeight: 5 // 线宽
    89. });
    90. this.map.add([polyline1]);
    91. },
    92. // 绘制圆点
    93. createMaker (path = []) {
    94. console.log(path, 'path--');
    95. path.forEach((v, idx) => {
    96. // 点标记显示内容,HTML要素字符串
    97. const markerContent = `
    98. ${v.msg}
    99. `;
  • const position = new this.AMap.LngLat(v.path[0], v.path[1]);
  • const marker = new this.AMap.Marker({
  • position: position,
  • // 将 html 传给 content
  • content: markerContent,
  • // 以 icon 的 [center bottom] 为原点
  • offset: new this.AMap.Pixel(-5, -5)
  • });
  • // 将 markers 添加到地图
  • this.map.add(marker);
  • });
  • setTimeout(_ => {
  • const list = document.querySelectorAll('.amap-maker-icon');
  • console.log(list, 'list');
  • for (let i = 0; i < list.length; i++) {
  • list[i].onclick = function () {
  • alert('点击了');
  • console.log(list[i], 'list[i]点击的点');
  • };
  • }
  • }, 4000);
  • },
  • // 地图初始化
  • intAmap (callBack) {
  • this.AMap = window.AMap;
  • this.AMap.plugin(['AMap.MouseTool', 'AMap.PolyEditor', 'AMap.ControlBar'], function () {
  • //TODO 创建控件并添加
  • });
  • const len = Math.ceil(pathList.length / 2); // 数组中间那个数据
  • const center = [pathList[len].path[0], pathList[len].path[1]];
  • this.map = new this.AMap.Map("amapContainer", {
  • center,
  • zoom: 6,
  • pitch: 80,
  • layers: [new AMap.TileLayer.Satellite()],
  • viewMode: '2D',//开启3D视图,默认为关闭
  • buildingAnimation: true,//楼块出现是否带动画
  • });
  • const setFeatures = ['bg', 'road', 'building', 'point'];
  • map.setFeatures(setFeatures); // 多个种类要素显示
  • this.map.addControl(new this.AMap.ControlBar());
  • if (callBack && typeof callBack == 'function') {
  • callBack();
  • this.drawPath(pathList.map(v => v.path));
  • this.createMaker(pathList);
  • }
  • },
  • }
  • };
  • script>
  • <style lang="scss" scoped>
  • ::v-deep#amapContainer {
  • height: 800px;
  • width: 100%;
  • .amap-maker-icon {
  • position: relative;
  • height: 10px;
  • width: 10px;
  • border-radius: 10px;
  • background: red;
  • &:hover {
  • .title {
  • display: block;
  • }
  • }
  • .title {
  • // display: none;
  • position: absolute;
  • top: -20px;
  • left: -70px;
  • width: 150px;
  • color: #333;
  • font-size: 10px;
  • border-radius: 5px;
  • background: rgba(256, 256, 256)
  • }
  • }
  • }
  • style>
  • 相关阅读:
    10个最流行的向量数据库【AI】
    kubernetes
    Java中使用JTS对空间几何计算(读取WKT、距离、点在面内、长度、面积、相交等)
    第十四章大数据和数据科学
    【linux】保存一份进程监视命令
    clickhouse读取kafka数据
    YouTrack 中如何设置邮件通知
    无法定位程序输入点kernel32.dll的解决方法
    vue项目中,多个数据并发请求
    mac的终端显示分支名称?mac的终端和idea中的terminal同时修改
  • 原文地址:https://blog.csdn.net/CodingNoob/article/details/133882519