google map 示例

代码
  1.   "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">  
  2. <html xmlns="http://www.w3.org/1999/xhtml" xmlns:v="urn:schemas-microsoft-com:vml">  
  3.   <head>  
  4.     <meta http-equiv="content-type" content="text/html; charset=utf-8"/>  
  5.     <title>Google Maps JavaScript API Exampletitle>  
  6.     <script src="http://maps.google.com/maps?file=api&v=2&key=ABQIAAAALZrWbwv15xcW6o6Rz2I9OBT8BhQlyUVBQhI7yb8dqdkP7sHdrRTkgtKBUMAsHSYcx-k3lrwvWHbe9w"  
  7.       type="text/javascript">script>  
  8.     <script type="text/javascript">  
  9.         
  10.     function load() {   
  11.       if (GBrowserIsCompatible()) {   
  12.            
  13.         // Create a base icon for all of our markers that specifies the shadow, icon   
  14.                 // dimensions, etc.   
  15.                 var baseIcon = new GIcon();   
  16.                 baseIcon.shadow = "http://www.google.com/mapfiles/shadow50.png";   
  17.                 baseIcon.iconSize = new GSize(20, 34);   
  18.                 baseIcon.shadowSize = new GSize(37, 34);   
  19.                 baseIcon.iconAnchor = new GPoint(9, 34);   
  20.                 baseIcon.infoWindowAnchor = new GPoint(9, 2);   
  21.                 baseIcon.infoShadowAnchor = new GPoint(18, 25);   
  22.   
  23.            
  24.         // Create our "tiny" marker icon   
  25.                 var icon = new GIcon();   
  26.                 icon.image = "http://labs.google.com/ridefinder/images/mm_20_red.png";   
  27.                 icon.shadow = "http://labs.google.com/ridefinder/images/mm_20_shadow.png";   
  28.                 icon.iconSize = new GSize(12, 20);   
  29.                 icon.shadowSize = new GSize(22, 20);   
  30.                 icon.iconAnchor = new GPoint(6, 20);   
  31.                 icon.infoWindowAnchor = new GPoint(5, 1);   
  32.   
  33.           
  34.         // Center the map on Palo Alto   
  35.                 var map = new GMap(document.getElementById("map"));   
  36.             //  map.addControl(new GSmallMapControl());   
  37.                 map.addControl(new GLargeMapControl());    
  38.                 //map.addControl(new GSmallZoomControl());   
  39.                 map.addControl(new GMapTypeControl());   
  40.                 map.centerAndZoom(new GPoint(106.083984375,36.94989178681327),13);   
  41.                    
  42.                    
  43.                 // Download the data in data.xml and load it on the map. The format we   
  44.                 // expect is:   
  45.                 // <markers>  
  46.                 //   <marker lat="37.441" lng="122.141"/>  
  47.                 //   <marker lat="37.322" lng="121.213"/>  
  48.                 // markers>  
  49.                 var request = GXmlHttp.create();   
  50.                 request.open("GET", "http://www.step1.cn/GoogleAPI/map/data.xml", true);   
  51.                 request.onreadystatechange = function() {   
  52.                 if (request.readyState == 4) {   
  53.                      var xmlDoc = request.responseXML;   
  54.                      var markers = xmlDoc.getElementsByTagName("marker");   
  55.                      for (var i = 0; i < markers.length; i++) {   
  56.                         var point = new GPoint(parseFloat(markers[i].getAttribute("lng")),   
  57.                              parseFloat(markers[i].getAttribute("lat")));   
  58.                       var marker = createMarker(point,i);   
  59.                       map.addOverlay(marker);   
  60.                      }   
  61.                     }   
  62.                 }   
  63.                 request.send(null);   
  64.   
  65.   
  66.                 // Creates a marker whose info window displays the given number   
  67.                 function createMarker(point, index) {    
  68.                      // Create a lettered icon for this point using our icon class from above   
  69.         var letter = String.fromCharCode("A".charCodeAt(0) + index);   
  70.         var icon = new GIcon(baseIcon);   
  71.         icon.image = "http://www.google.com/mapfiles/marker" + letter + ".png";   
  72.         var marker = new GMarker(point, icon);   
  73.          
  74.         // Show this marker's index in the info window when it is clicked   
  75.         var html = "Marker " + letter + "b>";   
  76.         GEvent.addListener(marker, "click", function() {   
  77.           marker.openInfoWindowHtml(html);   
  78.         });   
  79.          
  80.         return marker;   
  81.             }    
  82.                
  83.             // Add 10 random markers in the map viewport   
  84.             var bounds = map.getBoundsLatLng();   
  85.             var width = bounds.maxX - bounds.minX;   
  86.             var height = bounds.maxY - bounds.minY;   
  87.             for (var i = 0; i < 1; i++) {   
  88.                  var point = new GPoint(bounds.minX + width * Math.random(),   
  89.                             bounds.minY + height * Math.random());   
  90.              var marker = createMarker(point, i + 1);   
  91.                  map.addOverlay(marker);   
  92.             }   
  93.                
  94.                
  95.             // Add a polyline with 4 random points. Sort the points by longitude so that   
  96.       // the line does not intersect itself.   
  97.       var points = [];   
  98.       for (var i = 0; i < 5; i++) {   
  99.         points.push(new GPoint(bounds.minX + width * Math.random(),   
  100.                               bounds.minY + height * Math.random()));   
  101.       }   
  102.       points.sort(function(p1, p2) { return p1.x - p2.x; });   
  103.       map.addOverlay(new GPolyline(points));   
  104.           
  105.      var polyline = new GPolyline([new GPoint(116.1419, 37.4419),   
  106.                               new GPoint(122.1519, 40.4519)],   
  107.                               "#ff0000", 10);   
  108.       map.addOverlay(polyline);   
  109.            
  110.      }//end if   
  111.          
  112.          
  113.     } //end load()   
  114.       
  115.     script>  
  116.   head>  
  117.   <body onload="load()" onunload="GUnload()">  
  118.     <div id="message">div>  
  119.     <div id="map" style="width: 750px; height: 550px">div>  
  120.   body>  
  121. html>  
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值