-
Notifications
You must be signed in to change notification settings - Fork 1
/
07.html
88 lines (71 loc) · 3 KB
/
07.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="initial-scale=1.0, user-scalable=no" />
<link rel="stylesheet" type="text/css" href="css/main.css">
<link rel="stylesheet" type="text/css" href="css/control.css">
<link rel="stylesheet" type="text/css" href="css/directions.css">
<script type="text/javascript" src="https://maps.googleapis.com/maps/api/js?v=3.exp&sensor=false"></script>
</head>
<body>
<div id="directions-panel"></div>
<div id="map-canvas"></div>
<div id="control">
<input id="start" type="textbox" value="" placeholder="start"/>
<input id="end" type="textbox" value="" placeholder="end"/>
<input id="directions-button" type="button" value="Get Directions"/>
</div>
<script>
var SODA_LAT = 37.8757435;
var SODA_LONG = -122.25873230000002;
var directionsRenderer;
var directionsService;
function initialize() {
// Initialize directionsService, a DirectionsService object
// *** REPLACE null WITH YOUR CODE ***
directionsService = new google.maps.DirectionsService();
var mapOptions = {
zoom: 7,
center: new google.maps.LatLng(SODA_LAT, SODA_LONG)
};
var map = new google.maps.Map(document.getElementById('map-canvas'), mapOptions);
var directionsPanel = document.getElementById('directions-panel');
// Initialize directionsOptions, a DirectionsRendererOptions object
// set the following properties: map, panel
// *** REPLACE null WITH YOUR CODE ***
var directionsOptions = {
map: map,
panel: directionsPanel
};
// Initialize directionsRenderer, a DirectionsRenderer object
// *** REPLACE null WITH YOUR CODE ***
directionsRenderer = new google.maps.DirectionsRenderer(directionsOptions);
}
function calcRoute() {
var start = document.getElementById('start').value;
var end = document.getElementById('end').value;
// Initialize request, a DirectionsRequest object
// What are the three required properties of a DirectionsRequest?
// *** REPLACE null WITH YOUR CODE ***
var request = {
origin: start,
destination: end,
travelMode: google.maps.TravelMode.DRIVING
};
// Issue a directions search request.
// In the callback function, set the directions of directionsRenderer
// This is probably the most difficult task so far. Ask for help if you
// need it.
// hint: use directionsService to issue the search request.
// *** YOUR CODE HERE ***
directionsService.route(request, function(result, status) {
if (status == google.maps.DirectionsStatus.OK) {
directionsRenderer.setDirections(result);
}
});
}
google.maps.event.addDomListener(window, 'load', initialize);
document.getElementById("directions-button").onclick = calcRoute;
</script>
</body>
</html>