现在的位置: 首页JavaScript>正文
GOOGLE Map API 基本实例
2007年11月14日 JavaScript 暂无评论 ⁄ 被围观 阅读(1,681)+

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:v="urn:schemas-microsoft-com:vml">
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8"/>
<title>Google 地图 JavaScript API 示例</title>
<style type="text/css">
v\\:* {
behavior:url(#default#VML);
}
body{
font-size:12px;
}
</style>
<script src="http://www.blogg.cn/http://ditu.google.com/maps?file=api&amp;&v=2.x"
type="http://www.blogg.cn/text/javascript"></script>
<script type="text/javascript">
//<![CDATA[

function load() {
if (GBrowserIsCompatible()) {
var map = new GMap2(document.getElementById("map"));
map.addControl(new GLargeMapControl()); //地图控制
map.addControl(new GOverviewMapControl()); //缩略图
map.addControl(new GScaleControl());
map.setCenter(new GLatLng(40.83792120564548, 111.67177677154541), 14); //起始地图中心坐标

// 添加默认气泡提示
map.openInfoWindowHtml(new GLatLng(40.83792120564548, 111.67177677154541),"<b>西部数字网</b>");

// 添加一条编码折线
var polyline = new GPolyline([
new GLatLng(40.83792120564548, 111.67177677154541),
new GLatLng(40.83907381448265, 111.68160438537597),
new GLatLng(40.83978809722463, 111.69402837753296),
new GLatLng(40.845144972444885, 111.71454191207886)
], "#FF0000", 5);
map.addOverlay(polyline);

// 在地图上添加带气泡的标注
map.addOverlay(createMarker(new GLatLng(40.83792120564548, 111.67177677154541),"西部数字网"));
map.addOverlay(createMarker(new GLatLng(40.83907381448265, 111.68160438537597),"土默特中学"));
map.addOverlay(createMarker(new GLatLng(40.83978809722463, 111.69402837753296),"交警指挥中心"));
map.addOverlay(createMarker(new GLatLng(40.845144972444885, 111.71454191207886),"我的家"));

 

// 在给定的点上创建带编号的标注函数
function createMarker(point, msg) {
var marker = new GMarker(point);
GEvent.addListener(marker, "click", function() {
marker.openInfoWindowHtml("<b>" + msg + "</b>");
});
return marker;
}

// 获取鼠标单击处的坐标
GEvent.addListener(map, "click", function(marker, point) {
//事件触发时将有 2 个参数传入
var mapPoint;

if (marker) //标记
mapPoint=marker.getPoint();
else
mapPoint = point;

document.getElementById("message").innerHTML = mapPoint;
});

}
}

//]]>
</script>
</head>
<body onload="load()" onunload="GUnload()">
<div id="map" style="width: 800px; height: 600px"></div>
<div id="message"></div>
</body>
</html>

给我留言

留言无头像?


[face=9] [face=8] [face=7] [face=6] [face=5] [face=4] [face=3] [face=30] [face=2] [face=29] [face=28] [face=27] [face=26] [face=25] [face=24] [face=23] [face=22] [face=21] [face=20] [face=1] [face=19] [face=18] [face=17] [face=16] [face=15] [face=14] [face=13] [face=12] [face=11] [face=10] [em=9] [em=8] [em=7] [em=6] [em=5] [em=4] [em=3] [em=30] [em=2] [em=29] [em=28] [em=27] [em=26] [em=25] [em=24] [em=23] [em=22] [em=21] [em=20] [em=1] [em=19] [em=18] [em=17] [em=16] [em=15] [em=14] [em=13] [em=12] [em=11] [em=10] ;) :| :x :twisted: :roll: :oops: :o :mrgreen: :lol: :idea: :evil: :cry: :arrow: :P :D :?: :? :) :( :!: 8O 8)