uniapp 地图行车轨迹

文章目录

uniapp 地图行车轨迹

官网地图组件:https://uniapp.dcloud.net.cn/component/map.html

官网地图组件控制:https://uniapp.dcloud.net.cn/api/location/map.html#createmapcontext

1、画地图

html 复制代码
<map class="positioning-map"
     id="largeScreenMap"
     :latitude="中心纬度"
     :longitude="中心经度"
     :scale="5"
     :include-points="polyline[0].points"
     :markers="标记点"
     :polyline="路线"
     @markertap="点击标记点时触发"
></map>
js 复制代码
// 地图实例
onReady() {
	this._mapContext = uni.createMapContext("largeScreenMap", this);
}

2、切换地图中心点

js 复制代码
// 获取当前位置
 uni.getLocation({
    type: 'wgs84',
    success: function (res) {
        let { longitude, latitude } = res
        // 将地图中心移动到当前定位点,需要配合map组件的show-location使用
        _this._mapContext.moveToLocation({ longitude: +longitude, latitude: +latitude }) 
        _this.mapCenter = { lat: latitude, lng: longitude }
    }
});

3、画路线

js 复制代码
// 路线
let polyline = [{
    width: 8,
    points: [], // 经纬度数组 [{latitude: 0, longitude: 0}]
    arrowLine: true, //带箭头的线
    color: '#3591FC', // 线的颜色
}]

4、轨迹移动

js 复制代码
// nextPoint 下一个点,moving 是否继续行驶-用于暂停行驶
movePoint(){
	if(!this.polyline[0] return;
	let durationTime = Math.ceil(30000 / polyline[0].points.length)	//默认播放全程使用30秒,计算相连两点动画时长
	this._mapContext.translateMarker({ // 平移marker,带动画
    duration: durationTime,
    markerId: '当前标记点的id', 
    destination: { // 指定 marker 移动到的目标点
        latitude: this.polyline[0].points[this.nextPointIndex].latitude,
        longitude: this.polyline[0].points[this.nextPointIndex].longitude
    },
    animationEnd: res => { // 动画结束回调函数
        //播放结束,继续移动到下一个点,最后一个点时结束移动
        if (this.nextPoint < polyline[0].points.length - 1) {
            this.nextPoint++
            if (this.moving) {
                this.movePoint()
            }
        } else {
            this.nextPoint = 1
        }
    }
})
}

5、标记点及自定义内容

js 复制代码
let marker=[
	{
		id: number-必填,
		latitude: '纬度',
		longitude: '经度',
		width: 18, height: 25,
		callout:{ content: '结束',// 开始
                  bgColor: '#ffffff',
                  padding: 4,
                  borderRadius: 3,
                  display: 'ALWAYS'},// '自定义标记点上方的气泡窗口'- 纯文本内容 - content 显示标记内容,二选一
		customCallout:{name:'需要的数据',display: 'BYCLICK'},// '自定义气泡窗口' - 自定义窗口内容 - 使用cover-view覆盖 ,二选一
	}
]

自定义气泡窗口参考:uniapp map自定义气泡窗

相关推荐
结网的兔子2 天前
【前端开发】Web端迁移至 uni-app 及鸿蒙扩展方案对比
前端·uni-app·harmonyos
2501_915909062 天前
iOS 应用反调试技详解术 检测调试器的原理与防护实践
android·ios·小程序·https·uni-app·iphone·webview
AI多Agent协作实战派2 天前
AI多Agent协作系统实战(二十八):顶栏统一战争——从1个页面异常到31个页面全量对齐
数据库·人工智能·uni-app
00后程序员张2 天前
iOS加固技术路线全面解析:Bitcode模式、源码模式与汇编模式对比及爱加密优势
android·汇编·ios·小程序·uni-app·cocoa·iphone
2501_916008893 天前
iOS IPA文件反编译与打包操作方法,拆包分析防护和加固打包
android·macos·ios·小程序·uni-app·cocoa·iphone
name好难取诶3 天前
通过对云基座和离线基座的对比,帮助开发者理解如何在不同场景下选择合适的打包方案。 什么是“基座” 在 UniApp 中,基座(也称“ ...
开发语言·uni-app·php
2501_915921433 天前
iOS手游安全反外挂解决方案:基于Xcode的加固混淆特色详解
android·安全·ios·小程序·uni-app·iphone·xcode
2501_916007473 天前
iOS App分发教程 App Store、TestFlight 与 Ad Hoc 的配置与上传方法
android·ios·小程序·https·uni-app·iphone·webview
qq_316837753 天前
uniapp 打包APP 使用 Galacean Effects 的特效
uni-app
古韵4 天前
你的 uni-app 分页,一个 hook 搞定竞态和加载
javascript·vue.js·uni-app