提交 | 用户 | 时间
|
58d006
|
1 |
<!DOCTYPE html> |
A |
2 |
<html> |
|
3 |
<head> |
|
4 |
<meta charset="utf-8"> |
|
5 |
<title>GMaps.js — Travel Route</title> |
|
6 |
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script> |
|
7 |
<script src="http://maps.google.com/maps/api/js?sensor=true"></script> |
|
8 |
<script 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 |
var route; |
|
14 |
$(document).ready(function(){ |
|
15 |
$('#forward').attr('disabled', 'disabled'); |
|
16 |
$('#back').attr('disabled', 'disabled'); |
|
17 |
$('#get_route').click(function(e){ |
|
18 |
e.preventDefault(); |
|
19 |
map.getRoutes({ |
|
20 |
origin: [map.markers[0].getPosition().lat(), map.markers[0].getPosition().lng()], |
|
21 |
destination: [map.markers[map.markers.length-1].getPosition().lat(), map.markers[map.markers.length-1].getPosition().lng()], |
|
22 |
callback: function(e){ |
|
23 |
route = new GMaps.Route({ |
|
24 |
map: map, |
|
25 |
route: e[0], |
|
26 |
strokeColor: '#336699', |
|
27 |
strokeOpacity: 0.5, |
|
28 |
strokeWeight: 10 |
|
29 |
}); |
|
30 |
$('#forward').removeAttr('disabled'); |
|
31 |
$('#back').removeAttr('disabled'); |
|
32 |
} |
|
33 |
}); |
|
34 |
$('#forward').click(function(e){ |
|
35 |
e.preventDefault(); |
|
36 |
route.forward(); |
|
37 |
|
|
38 |
if(route.step_count < route.steps_length) |
|
39 |
$('#steps').append('<li>'+route.steps[route.step_count].instructions+'</li>'); |
|
40 |
}); |
|
41 |
$('#back').click(function(e){ |
|
42 |
e.preventDefault(); |
|
43 |
route.back(); |
|
44 |
|
|
45 |
if(route.step_count >= 0) |
|
46 |
$('#steps').find('li').last().remove(); |
|
47 |
}); |
|
48 |
}); |
|
49 |
map = new GMaps({ |
|
50 |
el: '#map', |
|
51 |
lat: -12.043333, |
|
52 |
lng: -77.028333, |
|
53 |
zoom: 16, |
|
54 |
height: '500px', |
|
55 |
click: function(e){ |
|
56 |
map.addMarker({ |
|
57 |
lat: e.latLng.lat(), |
|
58 |
lng: e.latLng.lng() |
|
59 |
}); |
|
60 |
} |
|
61 |
}); |
|
62 |
}); |
|
63 |
</script> |
|
64 |
</head> |
|
65 |
<body> |
|
66 |
<h1>GMaps.js — Travel route</h1> |
|
67 |
<div class="row"> |
|
68 |
<div class="span16"> |
|
69 |
<div id="map" class="large"></div> |
|
70 |
</div> |
|
71 |
<div class="span5"> |
|
72 |
<div class="row"> |
|
73 |
<a href="#" class="btn" id="get_route">Get route</a> |
|
74 |
<a href="#" class="btn" id="back">« Back</a> |
|
75 |
<a href="#" class="btn" id="forward">Forward »</a> |
|
76 |
</div> |
|
77 |
<div class="row"> |
|
78 |
<ul id="steps"> |
|
79 |
</ul> |
|
80 |
</div> |
|
81 |
</div> |
|
82 |
</div> |
|
83 |
</body> |
|
84 |
</html> |