这个是模拟的数据,用于测试,为了方便学习 弹出框信息都是固定的,以及操作都不是写的循环,实际开发用 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. Chrome插件开发

    参考文档: http://open.chrome.360.cn/extension_dev/overview.html 参考博文: http://www.cnblogs.com/mfryf/p/370 ...

  2. BootStrap学习------栅格

    使用Bootstrap前端框架-栅格 要点 1.使用Bootstrap需要引入的css和js: (1)bootstrap.min.js (2)bootstrap.min.css 2.栅格系统需要通过& ...

  3. Java-java中无符号类型的处理

    在Java中,不存在Unsigned无符号数据类型,但可以轻而易举的完成Unsigned转换. 方案一:如果在Java中进行流(Stream)数据处理,可以用DataInputStream类对Stre ...

  4. [Js/Jquery]table行转列

    摘要 在使用ews调用exhange的收件箱的并在h5页面显示邮件详情的时候,因为返回的每封邮件的内容都是htmlbody,没有textbody.每封邮件又没什么规律,用正则表达式来匹配内容并不合适, ...

  5. 正则表达式基础---转自 Python正则表达式指南 前边

    1. 正则表达式基础 1.1. 简单介绍 正则表达式并不是Python的一部分.正则表达式是用于处理字符串的强大工具,拥有自己独特的语法以及一个独立的处理引擎,效率上可能不如str自带的方法,但功能十 ...

  6. php各种编码集详解和以及在什么情况下进行使用

    字符是各种文字和符号的总称,包括各国家文字.标点符号.图形符号.数字等. 字符集是多个字符的集合,字符集种类较多,每个字符集包含的字符个数不同,常见字符集名称:ASCII字符集.GB2312字符集.B ...

  7. Junit初级编码(一)第一个Junit测试程序

    序,Junit测试是单元测试的一个框架,提供了很多方法,供我们快速开展单元测试.目前最新版本JAR包为4.12,官网地址为http://junit.org/ 一.第一个Junit测试程序 1 去官网下 ...

  8. [译]我是怎么构建Node.js程序的

    原文: http://blog.ragingflame.co.za/2015/4/1/how-i-build-nodejs-applications "保持简单, 保持模块化." ...

  9. [KOJ0574NOIP200406合并果子]

    [COJ0574NOIP200406合并果子] 试题描述 在一个果园里,多多已经将所有的果子打了下来,而且按果子的不同种类分成了不同的堆.多多决定把所有的果子合成一堆.    每一次合并,多多可以把两 ...

  10. SSH-Struts第三弹:传智播客视频教程第一天上午的笔记

    一. 框架概述1.三大框架 : 是企业主流 JavaEE 开发的一套架构 Struts2 + Spring + Hibernate 2. 什么是框架?为什么要学框架 ?框架 是 实现部分功能的代码 ( ...