forked from vivianhtlee/76_hackUST
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex_mike.html
189 lines (157 loc) · 8.95 KB
/
index_mike.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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
<html lang="en">
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<script src="https://maps.googleapis.com/maps/api/js?v=3.exp&sensor=false&libraries=places"></script>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-alpha.6/css/bootstrap.min.css" integrity="sha384-rwoIResjU2yc3z8GV/NPeZWAv56rSmLldC3R/AZzGRnGxQQKnKkoFVhFQhNUwEyJ" crossorigin="anonymous">
<script type="text/javascript" src="http://www.google.com/jsapi"></script>
<style type="text/css">
input{
padding:5px 15px; background:#ccc;
border:0 none;
border-radius: 5px;
border-radius: 5px;
}
html {
margin: 0 auto;
}
#container{
width: 100%;
margin: 100px 500px;
}
#map {
height: 100%;
}
</style>
</head>
<body>
<div id="container">
<form id="theForm">
<h3 id="reminder-start"> Enter your starting point:</h3>
<p> <input id="startingPoint" type="text" size="50"> </p>
<h3 id="reminder-end"> Enter your end point:</h3>
<p> <input id="endPoint" type="text" size="50"> </p>
<fieldset class="form-group">
<legend>Any preferred tunnel?</legend>
<div class="form-check">
<label class="form-check-label">
<input type="radio" class="form-check-input" name="optionsRadios" id="optionsRadios1" value="option1" checked>
None
</label>
</div>
<div class="form-check">
<label class="form-check-label">
<input type="radio" class="form-check-input" name="optionsRadios" id="optionsRadios2" value="option2">
Cross-Harbour Tunnel
</label>
</div>
<div class="form-check">
<label class="form-check-label">
<input type="radio" class="form-check-input" name="optionsRadios" id="optionsRadios3" value="option2">
Eastern Harbour Tunnel
</label>
</div>
<div class="form-check">
<label class="form-check-label">
<input type="radio" class="form-check-input" name="optionsRadios" id="optionsRadios4" value="option2">
Western Harbour Tunnel
</label>
</div>
</fieldset>
<button class="btn btn-primary" type="submit" id="submit-button">Confirm</button>
</form>
<div id="map" style="display:none;"></div>
</div>
<script type="text/javascript">
function initialize() {
var currentStartlocation;
var startPoint = document.getElementById('startingPoint');
var startAutocomplete = new google.maps.places.Autocomplete(startPoint);
var endPoint = document.getElementById('endPoint');
var endAutocomplete = new google.maps.places.Autocomplete(endPoint);
var geocoder = new google.maps.Geocoder();
google.maps.event.addListener(startAutocomplete, 'place_changed', function () {
var startPlace = startAutocomplete.getPlace();
var location = "Address: " + startPlace.formatted_address + "<br/>";
location += "Latitude: " + startPlace.geometry.location.lat() + "<br/>";
location += "Longitude: " + startPlace.geometry.location.lng();
});
google.maps.event.addListener(endAutocomplete, 'place_changed', function () {
var endPlace = endAutocomplete.getPlace();
var location2 = "Address: " + endPlace.formatted_address + "<br/>";
location2 += "Latitude: " + endPlace.geometry.location.lat() + "<br/>";
location2 += "Longitude: " + endPlace.geometry.location.lng();
});
$("#theForm").submit(function(e){
event.preventDefault();
var startLat;
var startLng;
try{
startLat = startAutocomplete.getPlace().geometry.location.lat();
startLng = startAutocomplete.getPlace().geometry.location.lng();
}catch(err){
startLat = currentStartlocation.lat();
startLng = currentStartlocation.lng();
}
var endLat = endAutocomplete.getPlace().geometry.location.lat();
var endLng = endAutocomplete.getPlace().geometry.location.lng();
var url = "path.html?start_lat="+startLat+"&&start_lng="+startLng+"&&end_lat="+endLat+"&&end_lng="+endLng;
window.location.href = url;
});
var map = new google.maps.Map(document.getElementById('map'), {
center: {lat: -34.397, lng: 150.644},
zoom: 6
});
var infoWindow = new google.maps.InfoWindow({map: map});
// Try HTML5 geolocation.
if (navigator.geolocation) {
navigator.geolocation.getCurrentPosition(function(position) {
var pos = {
lat: position.coords.latitude,
lng: position.coords.longitude
};
var latlng = {lat: pos.lat, lng: pos.lng};
console.log(latlng);
geocoder.geocode( {'location': latlng}, function(results, status)
{
if (status == google.maps.GeocoderStatus.OK)
{
map.setCenter(results[1].geometry.location);//center the map over the result
//place a marker at the location
$("#startingPoint").val(results[0].formatted_address);
currentStartlocation = results[0].geometry.location;
console.log(currentStartlocation);
var marker = new google.maps.Marker(
{
map: map,
position: results[0].geometry.location
});
} else {
alert('Geocode was not successful for the following reason: ' + status);
}
});
infoWindow.setPosition(pos);
infoWindow.setContent('Location found.');
map.setCenter(pos);
}, function() {
handleLocationError(true, infoWindow, map.getCenter());
});
} else {
// Browser doesn't support Geolocation
handleLocationError(false, infoWindow, map.getCenter());
}
function handleLocationError(browserHasGeolocation, infoWindow, pos) {
infoWindow.setPosition(pos);
infoWindow.setContent(browserHasGeolocation ?
'Error: The Geolocation service failed.' :
'Error: Your browser doesn\'t support geolocation.');
}
}
google.maps.event.addDomListener(window, 'load', initialize);
</script>
<script src="https://code.jquery.com/jquery-3.1.1.slim.min.js" integrity="sha384-A7FZj7v+d/sdmMqp/nOQwliLvUsJfDHW+k9Omg/a/EheAdgtzNs3hpfag6Ed950n" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/tether/1.4.0/js/tether.min.js" integrity="sha384-DztdAPBWPRXSA/3eYEEUWrWCy7G5KFbe8fFjk5JAIxUYHKkDx6Qin1DkWx51bBrb" crossorigin="anonymous"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-alpha.6/js/bootstrap.min.js" integrity="sha384-vBWWzlZJ8ea9aCX4pEW3rVHjgjt7zpkNpZk+02D9phzyeVkE+jo0ieGizqPLForn" crossorigin="anonymous"></script>
</body>
</html>