最簡單的google地圖代碼

註冊使用 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&amp;v=2&amp;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()">
    <div id="webmap" style="width: 500px; height: 500px"></div>
  </body>
</html>
例子中
A 使用 script 標籤包含 Google 地圖 API JavaScript。
B 創建名爲“webmap”的 div 元素來包含地圖。
C 編寫 JavaScript 函數創建“map”對象。
D 將地圖的中心設置爲指定的地理點。
E 從 body 標籤的 onLoad 事件初始化地圖對象。

map.setCenter(new GLatLng(88, 99), 11); 裏面的參數88,99爲所在位置的經緯度,11爲縮放大小,獲得你所在位置的

座標可通過地圖找到你所在的位置,然後右擊選擇菜單中的“這兒是什麼”即可在搜索框中顯示出座標了
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章