google API 点连线
这个是模拟的数据,用于测试,为了方便学习 弹出框信息都是固定的,以及操作都不是写的循环,实际开发用 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 /> '; 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 /> ';
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 点连线的更多相关文章
- 借用Google API在线生成网站二维码地址方法
二维码其实很早就出现了,在国外很多年前就已经在应用了,国内这两年才开始异常的火爆,智能手机的发展,以及微博.微信等移动应用带动了二维码的普及.那么,如果为网址在线生成二维码呢?下面我们就来介绍一下Go ...
- [Java] - Google API调用
由于Google已经完成被墙,要上Google必需使用代理或VPN. 这里使用的是Google的GoAgent代理做开发.(如何使用GoAgent,这里不写了,忽略500字.....) 本地测试的Go ...
- PHP二维码生成的方法(google APi,PHP类库,libqrencode等)
原文地址: http://blog.csdn.net/liuxinmingcode/article/details/7910975 ================================== ...
- Google API在线生成二维码的方法
1.先看一个实例,是用Google API生成西部e网的网站地址www.weste.net二维码的方法: http://chart.apis.google.com/chart?cht=qr&c ...
- 缺少google api密钥,因此chromium的部分功能将无法使用”的解决办法
使用Chromium时会遇到 "缺少google api密钥,因此chromium的部分功能将无法使用"提示,google了一下 setx Google_API_K ...
- 利用google api生成二维码名片例子
二维条码/二维码可以分为堆叠式/行排式二维条码和矩阵式二维条码.堆叠式/行排式二维条码形态上是由多行短截的一维条码堆叠而成:矩阵式二维条码以矩阵的形式组成,在矩阵相应元素位置上用“点”表示二进制“1” ...
- google API的.NET库
Goolge发布了一个新的google API .NET库,是一个Portable Class Library,所以无论是.NET,WinTRy,Windows Phone或者Silverlight都 ...
- Google API v3 设置Icon问题处理
1.查看API实现 //虽然比较符合API实现的思想但这个没法; //会产生Uncaught TypeError: undefined is not a function //google API n ...
- ecshop使用Google API及OAuth2.0登录授权(PHP)
一.申请clientID https://console.developers.google.com/project 二.开启Google+ API权限 https://console.develop ...
随机推荐
- 并发下常见的加锁及锁的PHP具体实现代码(转)
在最近的项目中有这样的场景 1.生成文件的时候,由于多用户都有权限进行生成,防止并发下,导致生成的结果出现错误,需要对生成的过程进行加锁,只容许一个用户在一个时间内进行操作,这个时候就需要用到锁了,将 ...
- 【8-23】node.js学习笔记
Node入门 //请求(require)Node.js自带的 http 模块,并且把它赋值给 http 变量 //变成了一个拥有所有 http 模块所提供的公共方法的对象 var http = req ...
- linuxMint設置窗口最大最小化
linuxMint下面用键盘快速让窗口最大化和最小化
- PHP弹出提示框并跳转到新页面即重定向到新页面
本文为大家介绍下使用PHP弹出提示框并跳转到新页面,也就是大家所认为的重定向,下面的示例大家可以参考下 这两天写一个demo,需要用到提示并跳转,主要页面要求不高,觉得没必要使用AJAX,JS等, ...
- 2015年11月26日 Java基础系列(一)之String与StringBuffer与StringBuilder的区别
序,StringBuffer是线程安全的,StringBuilder是线程不安全的,但是StringBuilder操作速度快,因此在使用时要根据场景合理选择. StringBuffer和StringB ...
- JavaScript数组属性与方法
Array 对象属性 属性 描述 constructor 返回对创建此对象的数组函数的引用. length 设置或返回数组中元素的数目. prototype 使您有能力向对象添加属性和方法. Arra ...
- 可编辑select
<html> <head> <meta http-equiv="Content-Type" content="text/html; char ...
- 2015baidu复赛 矩形面积(包凸 && ps:附quickhull模板)
矩形面积 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submis ...
- uva.10020 Minimal coverage(贪心)
10020 Given several segments of line (int the X axis) with coordinates [Li, Ri]. You are to choose t ...
- 北京程序员 VS 硅谷程序员(转)
夫妻双码农,北京 or 硅谷,值得吗? http://mp.weixin.qq.com/s?__biz=MzA5MzE4MjgyMw==&mid=401228574&idx=1& ...