免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
论坛 程序设计 Web开发 gmap
最近访问板块 发新帖
查看: 1988 | 回复: 1
打印 上一主题 下一主题

gmap [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2012-02-19 13:41 |只看该作者 |倒序浏览
gmap

Js代码
  1. <html>   
  2. <head>   
  3. <meta name="viewport" content="initial-scale=1.0, user-scalable=no" />   
  4. <meta http-equiv="content-type" content="text/html; charset=UTF-8"/>   
  5. <title>画线</title>   
  6. <link href="http://code.google.com/apis/maps/documentation/javascript/examples/default.css" rel="stylesheet" type="text/css" />   
  7. <script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=true"></script>   
  8.    
  9. <script type="text/javascript">   
  10.    
  11.   var poly;   
  12.   var map;   
  13.   var directionsDisplay;   
  14.   var directionsService = new google.maps.DirectionsService();   
  15.    
  16.   
  17.    var geocoder;   
  18.   function initialize() {   
  19.      geocoder = new google.maps.Geocoder();   
  20.     var centerPoint = new google.maps.LatLng(23.0999442125314, 113.203125);   
  21.     var myOptions = {   
  22.       zoom: 4,   
  23.       center: centerPoint,   
  24.       mapTypeId: google.maps.MapTypeId.ROADMAP   
  25.     };   
  26.    
  27.     map = new google.maps.Map(document.getElementById('map_canvas'), myOptions);   
  28.    
  29.     var polyOptions = {   
  30.       strokeColor: 'red',   
  31.       strokeOpacity: 1.0,   
  32.       strokeWeight: 3   
  33.     }   
  34.     poly = new google.maps.Polyline(polyOptions);   
  35.     poly.setMap(map);   
  36.     directionsDisplay = new google.maps.DirectionsRenderer();   
  37.     directionsDisplay.setMap(map);   
  38.      var point = new google.maps.LatLng (37.37015718405753, 114.609375);   
  39.       addLatLng(point,'A点','理','2011-11-21');   
  40.          
  41.        var point = new google.maps.LatLng (39.13006024213511, 115.48828125);   
  42.       addLatLng(point,'B点','宁','2012-01-01');   
  43.          
  44.       var point = new google.maps.LatLng(23.241346102386135, 114.169921875);   
  45.       addLatLng(point,'广州','xx','2012-01-16');   
  46.        //calcRoute('37.37015718405753, 114.609375','39.13006024213511, 115.48828125');   
  47.        //calcRoute('39.13006024213511, 115.48828125','23.241346102386135, 114.169921875');   
  48.   }   
  49.   </script>   
  50.      
  51.   <script type="text/javascript">   
  52.    
  53.   function addLatLng(point,mytitle,myname,time) {   
  54.     var path = poly.getPath();   
  55.     path.push(point);   
  56.    
  57.     var marker = new google.maps.Marker({   
  58.       position: point,   
  59.       title: mytitle,   
  60.       map: map   
  61.     });   
  62.       
  63.     //查询地址   
  64.    // codeLatLng(point);   
  65.     geocoder.geocode({'latLng': point}, function(results, status) {   
  66.          if (status == google.maps.GeocoderStatus.OK) {   
  67.              if (results[1]) {   
  68.                   
  69.                     var con='姓名: '+myname +'<br> 时间: '+time+' <br>所在地:'+ results[1].formatted_address;   
  70.             attachSecretMessage(marker,con);   
  71.                 }   
  72.             } else {   
  73.   
  74.         alert("Geocoder failed due to: " + status);   
  75.   
  76.       }   
  77.         });   
  78.   
  79.   }   
  80.    
  81.    
  82. function attachSecretMessage(marker,mycontent) {   
  83.   var infowindow = new google.maps.InfoWindow(   
  84.       { content: mycontent,   
  85.         size: new google.maps.Size(50,50)   
  86.       });   
  87.          
  88.   google.maps.event.addListener(marker, 'click', function(response) {   
  89.       
  90.       
  91.       
  92.     infowindow.open(map,marker);   
  93.     map.setCenter(marker.position);   
  94.      map.setZoom(6);   
  95.   });   
  96. }   
  97.    
  98. //起点 终点   
  99. function calcRoute(start,end) {   
  100.      
  101.   var request = {   
  102.     origin:start,   
  103.     destination:end,   
  104.     travelMode: google.maps.DirectionsTravelMode.DRIVING   
  105.   };   
  106.   directionsService.route(request, function(result, status) {   
  107.     if (status == google.maps.DirectionsStatus.OK) {   
  108.       directionsDisplay.setDirections(result);   
  109.     }   
  110.   });   
  111. }   
  112.    
  113. </script>   
  114. </head>   
  115. <body onload="initialize()">   
  116.   <div id="map_canvas"></div>   
  117. </body>   
  118. </html>   
复制代码

论坛徽章:
0
2 [报告]
发表于 2012-02-19 15:58 |只看该作者
谢谢分享
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP