Google地图实时轨迹

基于谷歌地图的marker和Polyline,做的行驶轨迹渲染。关于坐标会有偏移问题。最好上报点位的时候进行纠偏、去噪、绑路。

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="viewport" content="initial-scale=1.0, user-scalable=no" />
<meta charset="utf-8" />
<title>Google地图轨迹实时测试</title>
<style type="text/css">
body, html,#mapContainer {width: 100%;height: 100%;overflow: hidden;margin:0;z-index: 1;}
</style>
<script src="http://maps.googleapis.com/maps/api/js?v=3&key=谷歌key&sensor=false&libraries=drawing,places"></script>
<script language="javascript">
var map;
var lineSymbol = {
	path: google.maps.SymbolPath.FORWARD_CLOSED_ARROW,
	//scale: 2,
	strokeColor: "#000"
  };
var lineCoordinates = [
	new google.maps.LatLng(30.65721817, 104.06594494),
	new google.maps.LatLng(30.656361,104.065477 ),
	new google.maps.LatLng(30.652691, 104.066058  ),
	new google.maps.LatLng( 30.652485,104.068823 ),
	new google.maps.LatLng(30.655939,104.071278 )
  ];
function initialize() {
 
      var mapOptions = {
        center: new google.maps.LatLng(30.65721817, 104.06594494),
        zoom: 16,
        panControl: true,
        zoomControl: true,
        mapTypeControl: true,
        scaleControl: true,
        overviewMapControl: true,
        mapTypeId: google.maps.MapTypeId.ROADMAP
      };
 
      map = new google.maps.Map(document.getElementById('mapContainer'),mapOptions);
	  addMarker(lineCoordinates[0],'car.png','起点');
      //圆移动
	  line = new google.maps.Polyline({
		path: lineCoordinates,
		icons: [{
		  icon: lineSymbol,
		  offset: '0%'
		}],
		map: map,
		strokeColor: "#f30", // 线条颜色 红色
		strokeOpacity: 0.7, // 透明度 70%
		strokeWeight: 5 // 宽度 5像素
	  });

	  animateCircle();
		  
		  	
}
function addMarker(position, icon,title) {
	// Add a new marker at the new plotted point on the polyline.
	new google.maps.Marker({
		position : position,
		title : title,
		map : map,
		icon : icon
	});
}
/**
* 设置点位并启动动画移动特效
*/
function setLatLng(lat,lng){
	var latLngObj = new google.maps.LatLng(lat,lng);
	line.set("icons",null);
	line = new google.maps.Polyline({
		path: [lineCoordinates[lineCoordinates.length-1],latLngObj],
		icons: [{
		  icon: lineSymbol,
		  offset: '0%'
		}],
		map: map,
		strokeColor: "#f30", // 线条颜色 红色
		strokeOpacity: 0.7, // 透明度 70%
		strokeWeight: 5 // 宽度 5像素
	  });
	  lineCoordinates.push(latLngObj);
	var path = line.getPath(latLngObj);
	//path.push(new google.maps.LatLng(30.665939,104.071278));
	//path.push(latLngObj);
	map.setCenter(latLngObj);
	 animateCircle();
}
/**
* 动态加载 点位数据 ,进行动画显示
* 此处可使用ajax 拉取点位数据,
*/
function dynamic(){
	window.setInterval(function() {
	var lat= 30.655939+Math.random().toFixed(3)/100;
	var lng=104.06594494+Math.random().toFixed(5)/100;
	setLatLng(lat,lng);
	},5000);
}
//移动
function animateCircle() {
    var count = 0;
    var animate1=window.setInterval(function() {
      count = (count + 1) % 200;
      var icons = line.get('icons');
      icons[0].offset = (count / 2) + '%';
      line.set('icons', icons);
      //终点停车
      
      if((count / 2)>=99){
          clearInterval(animate1);
      }
      
  }, 10);
}
google.maps.event.addDomListener(window, 'load', initialize);

</script> 
 
</head> 
 
<body> 
 
  <div id="mapContainer"></div> 
 
</body> 
 
</html>

  • 0
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
根据提供的引用内容,可以了解到在QT软件开发中,有一个轨迹回放软件,该软件结合了百度地图和Qt,并使用了常用的GNSS定位模块获取经纬度信息。然而,需要注意的是,常用的GNSS定位模块得到的经纬度是WGS84坐标系下的坐标,而国内的地图产品不允许直接使用GPS坐标,因此目前并没有直接使用谷歌地图的相关内容提及。 从引用中可以看出,该软件主要包括以下几个步骤: 1. 准备百度地图,并使用QWebEngineView显示地图的Html内容。 2. 在QT软件开发中实时绘制轨迹,并设定航点。 3. 使用MapChannel实现百度地图与QT软件的交互。 关于地图坐标,文中提到了常用的GNSS定位模块得到的经纬度是WGS84坐标系下的坐标。而国内的地图产品,包括百度地图,都不允许直接使用GPS坐标。因此,在使用百度地图时,需要将WGS84坐标系下的经纬度转换为百度坐标系下的经纬度。 综上所述,根据提供的引用内容,目前没有直接使用谷歌地图的相关信息。该轨迹回放软件是基于QT开发,并结合了百度地图来实现地图显示和绘制轨迹的功能。<span class="em">1</span><span class="em">2</span><span class="em">3</span> #### 引用[.reference_title] - *1* *2* *3* [使用QT嵌入百度地图开发高B格岸基监控软件](https://blog.csdn.net/qq_43015524/article/details/122674408)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_1"}}] [.reference_item style="max-width: 100%"] [ .reference_list ]

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值