註冊使用 Google 地圖先登陸
http://code.google.com/intl/zh-CN/apis/maps/signup.html、
申請之後獲得的代碼加入網頁中,下面是一個簡單的例子
<!DOCTYPE html "-//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">
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8"/>
<title>Google Maps JavaScript API Example</title>
<script src="http://ditu.google.cn/maps?file=api&v=2&key=abcdefg&sensor=true_or_false"
type="text/javascript"></script>
<script type="text/javascript">
function wb() {
if (GBrowserIsCompatible()) {
var map = new GMap2(document.getElementById("webmap"));
map.setCenter(new GLatLng(88, 99), 11);
}
}
</script>
</head>
<body onunload="GUnload()">
<p id="webmap" style="width: 500px; height: 500px"></p>
</body>
</html>
例子中
A 使用 script 標簽包含 Google 地圖 API JavaScript。
B 創建名為“webmap”的 p 元素來包含地圖。
C 編寫 JavaScript 函數創建“map”對象。
D 將地圖的中心設置為指定的地理點。
E 從 body 標簽的 onLoad 事件初始化地圖對象。
map.setCenter(new GLatLng(88, 99), 11); 裡面的參數88,99為所在位置的經緯度,11為縮放大小,獲得你所在位置的
坐標可通過地圖找到你所在的位置,然後右擊選擇菜單中的“這兒是什麼”即可在搜索框中顯示出坐標瞭
作者“java學習”