Administrator
2022-09-14 58d006e05dcf2a20d0ec5367dd03d66a61db6849
提交 | 用户 | 时间
58d006 1 <!DOCTYPE html>
A 2 <html>
3 <head>
4   <meta charset="utf-8">
5   <title>GMaps.js &mdash; Routes</title>
6   <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.4/jquery.min.js"></script>
7   <script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=true"></script>
8   <script type="text/javascript" src="../gmaps.js"></script>
9   <link rel="stylesheet" href="http://twitter.github.com/bootstrap/1.3.0/bootstrap.min.css" />
10   <link rel="stylesheet" type="text/css" href="examples.css" />
11   <script type="text/javascript">
12     var map;
13     $(document).ready(function(){
14       map = new GMaps({
15         el: '#map',
16         lat: -12.043333,
17         lng: -77.028333
18       });
19       map.travelRoute({
20         origin: [-12.044012922866312, -77.02470665341184],
21         destination: [-12.090814532191756, -77.02271108990476],
22         travelMode: 'driving',
23         step: function(e){
24           $('#instructions').append('<li>'+e.instructions+'</li>');
25           $('#instructions li:eq('+e.step_number+')').delay(450*e.step_number).fadeIn(200, function(){
26             map.drawPolyline({
27               path: e.path,
28               strokeColor: '#131540',
29               strokeOpacity: 0.6,
30               strokeWeight: 6
31             });  
32           });
33         }
34       });
35     });
36   </script>
37 </head>
38 <body>
39   <h1>GMaps.js &mdash; Routes</h1>
40   <div class="row">
41     <div class="span11">
42       <div id="map"></div>
43       <ul id="instructions">
44       </ul>
45     </div>
46     <div class="span6">
47       <p>You can travel a route, step by step, this way:</p>
48       <pre>map.travelRoute({
49   origin: [-12.044012922866312, -77.02470665341184],
50   destination: [-12.090814532191756, -77.02271108990476],
51   travelMode: 'driving',
52   step: function(e){
53     $('#instructions').append('&lt;li&gt;'+e.instructions+'&lt;/li&gt;');
54     $('#instructions li:eq('+e.step_number+')').delay(450*e.step_number).fadeIn(200, function(){
55       map.drawPolyline({
56         path: e.path,
57         strokeColor: '#131540',
58         strokeOpacity: 0.6,
59         strokeWeight: 6
60       });  
61     });
62   }
63 });</pre>
64       <p>Same as <code>drawRoute</code>, you must define an <strong>origin</strong>, <strong>destination</strong> and <code>travelMode</code>. Also, you must define the function that GMaps will call every step in the route.</p>
65     </div>
66   </div>
67 </body>
68 </html>