这个是模拟的数据,用于测试,为了方便学习 弹出框信息都是固定的,以及操作都不是写的循环,实际开发用 setInterval 或者for 以减少冗余。

<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="initial-scale=1.0, user-scalable=no">
<meta charset="utf-8">
<title>Simple Polylines</title>
<style>
html, body, #map-canvas
{
height: %;
margin: 0px;
padding: 0px;
}
</style>
<script src="http://maps.google.com/maps/api/js?v=3.1&sensor=true" type="text/javascript"></script>
<script>
var flightPlanCoordinates;
var map;
var allMarker = [];
function initialize() {
var mapOptions = {
zoom: ,
center: new google.maps.LatLng(, -),
mapTypeId: google.maps.MapTypeId.TERRAIN
}; map = new google.maps.Map(document.getElementById('map-canvas'), mapOptions); flightPlanCoordinates = [
new google.maps.LatLng(37.772323, -122.214897),
new google.maps.LatLng(21.291982, -157.821856),
new google.maps.LatLng(-18.142599, 178.431),
new google.maps.LatLng(-27.46758, 153.027892)
]; var flightPath = new google.maps.Polyline({
path: flightPlanCoordinates,
strokeColor: "#00FF33",
strokeOpacity: ,
strokeWeight:
});
flightPath.setMap(map);
} google.maps.event.addDomListener(window, 'load', initialize); var html = '<b>鲁B 897HE</b><br />2013-12-22 08:47:11<br />里程:0.00公里<br />纬度:36.10631,经度:120.36730<br />方向:正东,速度:16.00公里/小时<br />&nbsp;&nbsp;'; setTimeout(function () {
var oPolygon = {};
oPolygon[""] = new google.maps.Marker({
position: flightPlanCoordinates[],
map: map
}); var infowindow2 = new google.maps.InfoWindow({ content: html });
google.maps.event.addListener(oPolygon[""], 'click', function () {
infowindow2.open(map, oPolygon[""]);
});
infowindow2.open(map, oPolygon[""]);
window.addMarker = oPolygon;
}, ); setTimeout(function () {
var oPolygon = {};
oPolygon[""] = new google.maps.Marker({
position: flightPlanCoordinates[],
map: map
}); clearMap(flightPlanCoordinates[]);
var infowindow2 = new google.maps.InfoWindow({ content: html });
google.maps.event.addListener(oPolygon[""], 'click', function () {
infowindow2.open(map, oPolygon[""]);
});
infowindow2.open(map, oPolygon[""]);
window.addMarker = oPolygon;
}, ); setTimeout(function () {
var oPolygon = {};
oPolygon[""] = new google.maps.Marker({
position: flightPlanCoordinates[],
map: map
});
clearMap(flightPlanCoordinates[]); setView(flightPlanCoordinates[]); var infowindow2 = new google.maps.InfoWindow({ content: html });
google.maps.event.addListener(oPolygon[""], 'click', function () {
infowindow2.open(map, oPolygon[""]);
});
infowindow2.open(map, oPolygon[""]);
window.addMarker = oPolygon;
}, ); setTimeout(function () {
var oPolygon = {};
oPolygon[""] = new google.maps.Marker({
position: flightPlanCoordinates[],
map: map
});
setView(flightPlanCoordinates[]);
clearMap(flightPlanCoordinates[]);
var infowindow2 = new google.maps.InfoWindow({ content: html });
google.maps.event.addListener(oPolygon[""], 'click', function () {
infowindow2.open(map, oPolygon[""]);
});
infowindow2.open(map, oPolygon[""]);
window.addMarker = oPolygon;
}, ); function setView(obj) {
var LatLngBounds = map.getBounds();
var isMap = LatLngBounds.contains(obj);
if (!isMap) {
map.panTo(obj);
}
} function clearMap() {
for (var i in window.addMarker) {
window.addMarker[i].setMap(null);
}
}
</script>
</head>
<body>
<div id="map-canvas">
</div>
</body>
</html>

改进和优化

<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="initial-scale=1.0, user-scalable=no">
<meta charset="utf-8">
<title>Simple Polylines</title>
<style>
html, body, #map-canvas
{
height: 100%;
margin: 0px;
padding: 0px;
}
</style>
<script src="http://maps.google.com/maps/api/js?v=3.1&sensor=true" type="text/javascript"></script>
<script>
var flightPlanCoordinates;
var map;
var allMarker = [];
function initialize() {
var mapOptions = {
zoom: 3,
center: new google.maps.LatLng(0, -180),
mapTypeId: google.maps.MapTypeId.TERRAIN
};

map = new google.maps.Map(document.getElementById('map-canvas'), mapOptions);

flightPlanCoordinates = [
new google.maps.LatLng(37.772323, -122.214897),
new google.maps.LatLng(21.291982, -157.821856),
new google.maps.LatLng(-18.142599, 178.431),
new google.maps.LatLng(-27.46758, 153.027892)
];

var flightPath = new google.maps.Polyline({
path: flightPlanCoordinates,
strokeColor: "#00FF33",
strokeOpacity: 1,
strokeWeight: 6
});
//flightPath.setMap(map);
}

google.maps.event.addDomListener(window, 'load', initialize);

var html = '<b>鲁B 897HE</b><br />2013-12-22 08:47:11<br />里程:0.00公里<br />纬度:36.10631,经度:120.36730<br />方向:正东,速度:16.00公里/小时<br />&nbsp;&nbsp;';

var index = 0;
var newMarkers = [], lastnewMarker = [], infoMsgList=[];
var ss = setInterval(function () {
if (index > flightPlanCoordinates.length - 1) {
clearInterval(ss);
return;
}
var newMarker = new google.maps.Marker({
position: flightPlanCoordinates[index],
map: map
});
var infoMsg = new google.maps.InfoWindow({ content: html });
google.maps.event.addListener(newMarker, 'click', function () {
infoMsg.open(map, newMarker);
});
infoMsg.open(map, newMarker);
newMarkers.push(newMarker);
infoMsgList.push(infoMsg);
if (index > 0) {
newMarkers[index - 1].setIcon("green_01.gif");
infoMsgList[index - 1].close();
}
index++;
}, 2000);

function setView(obj) {
var LatLngBounds = map.getBounds();
var isMap = LatLngBounds.contains(obj);
if (!isMap) {
map.panTo(obj);
}
}

function clearMap() {
for (var i in window.addMarker) {
window.addMarker[i].setMap(null);
}
}
</script>
</head>
<body>

<div id="map-canvas">
</div>
</body>
</html>

google API 点连线的更多相关文章

  1. 借用Google API在线生成网站二维码地址方法

    二维码其实很早就出现了,在国外很多年前就已经在应用了,国内这两年才开始异常的火爆,智能手机的发展,以及微博.微信等移动应用带动了二维码的普及.那么,如果为网址在线生成二维码呢?下面我们就来介绍一下Go ...

  2. [Java] - Google API调用

    由于Google已经完成被墙,要上Google必需使用代理或VPN. 这里使用的是Google的GoAgent代理做开发.(如何使用GoAgent,这里不写了,忽略500字.....) 本地测试的Go ...

  3. PHP二维码生成的方法(google APi,PHP类库,libqrencode等)

    原文地址: http://blog.csdn.net/liuxinmingcode/article/details/7910975 ================================== ...

  4. Google API在线生成二维码的方法

    1.先看一个实例,是用Google API生成西部e网的网站地址www.weste.net二维码的方法: http://chart.apis.google.com/chart?cht=qr&c ...

  5. 缺少google api密钥,因此chromium的部分功能将无法使用”的解决办法

            使用Chromium时会遇到 "缺少google api密钥,因此chromium的部分功能将无法使用"提示,google了一下 setx Google_API_K ...

  6. 利用google api生成二维码名片例子

    二维条码/二维码可以分为堆叠式/行排式二维条码和矩阵式二维条码.堆叠式/行排式二维条码形态上是由多行短截的一维条码堆叠而成:矩阵式二维条码以矩阵的形式组成,在矩阵相应元素位置上用“点”表示二进制“1” ...

  7. google API的.NET库

    Goolge发布了一个新的google API .NET库,是一个Portable Class Library,所以无论是.NET,WinTRy,Windows Phone或者Silverlight都 ...

  8. Google API v3 设置Icon问题处理

    1.查看API实现 //虽然比较符合API实现的思想但这个没法; //会产生Uncaught TypeError: undefined is not a function //google API n ...

  9. ecshop使用Google API及OAuth2.0登录授权(PHP)

    一.申请clientID https://console.developers.google.com/project 二.开启Google+ API权限 https://console.develop ...

随机推荐

  1. <Web 之困 现代Web应用安全指南>一本好书 69.00?

    NET代码安全 界面漏洞防范与程序优化 一. SQL 注入攻击的源头 1. 过滤或转移危险字符 2.  使用SqlParameter类:.NET 框架有一个叫做SqlParameter 的集合类型,可 ...

  2. C# 获取指定接口的所有实现类

    var types = AppDomain.CurrentDomain.GetAssemblies() .SelectMany(a => a.GetTypes().Where(t => t ...

  3. hibernate4中取得connection的方法

    在hibernate3中,使用了c3p0连接池,尝试了多种办法取得connection对象,以下两种可以使用. Java代码  Connection conn; // 方法1:hibernate4中将 ...

  4. Java中符号位扩展

    第一个例子: byte b=-100;b在内存中是以补码的形式存贮的:1001 1100 如果执行char c=(char)b;如3楼企鹅先生所说:b要先变为int,这时增加的位全要用b的符号位填充( ...

  5. DWZ框架中ajax提交文件表单的处理(关闭当前dialog + 刷新父级navTab)

    先重点关注两个js文件:dwz.ajax.js和dwz.core.js 流程: 1.回调iframeCallback <form xx enctype="multipart/form- ...

  6. Java中为什么有abstract interface 修饰类?

    如果有人问你为什么有abstract interface 修饰类,答案一定是他看到的这种方式一定是反编译出来的结果.实际中abstract interface和interface修饰的类没有区别. 下 ...

  7. VTK初学一,a Mesh from vtkImageData—球冠

    #ifndef INITIAL_OPENGL #define INITIAL_OPENGL #include <vtkAutoInit.h> VTK_MODULE_INIT(vtkRend ...

  8. Ruby学习之module

    我们可以认为module是一个专门存放一系列方法和常量的工具箱. module和class非常像, 只是module不能创建实例也不能有子类, 它们仅仅能存放东西. 例如: module Circle ...

  9. eclipse无法自动识别出svn项目

    因为重新安装了svn插件,重启后发现原来的svn项目无法自动识别出来,连Team->Share Project都没有,而本地用tortoiseSvn是可以正常操作的. 后来我把项目删除然后重新导 ...

  10. OC第二节 —— NSString和NSMutableString

    1.为什么需要NSString对象        答:在OC中创建字符串时,一般不使用C的方法,    因为C将字符串作为字符数组,所以在操作时会有很多不方便的地方,    在Cocoa中NSStri ...