当前位置:编程学习 > JAVA >>

最简单的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&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()">
    <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为缩放大小,获得你所在位置的
坐标可通过地图找到你所在的位置,然后右击选择菜单中的“这儿是什么”即可在搜索框中显示出坐标了

作者“java学习”

补充:软件开发 , Java ,
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,