forked from Cherchercher/SafeCommuteSBHack2018
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
executable file
·410 lines (362 loc) · 14.9 KB
/
index.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
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
<!DOCTYPE html>
<html id="loginHTML" lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<meta name="description" content="">
<link href="style.css" rel="stylesheet" type="text/css">
<link href="http://maxcdn.bootstrapcdn.com/font-awesome/4.3.0/css/font-awesome.min.css" rel="stylesheet">
<link rel="stylesheet" type="text/css" href="http://fonts.googleapis.com/css?family=Merriweather">
<meta name="author" content="Cher Huang, Ishani, Haejin Jo">
<title>Breathr</title>
<!-- Bootstrap core CSS -->
<link href="vendor/bootstrap/css/bootstrap.min.css" rel="stylesheet">
<!-- Custom styles -->
<style>
body {
padding-top: 54px;
}
@media (min-width: 992px) {
body {
padding-top: 56px;
}
}
#googleMap {
width:100%;
height:360px;
margin-top:10px;
}
.black {
color:white;
}
.options{
margin-top:10px;
}
</style>
</head>
<body>
<!-- Navigation -->
<nav class="navbar navbar-expand-lg navbar-dark bg-info fixed-top">
<div class="container">
<a class="navbar-brand" href="#">Breathr</a>
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarResponsive" aria-controls="navbarResponsive" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="navbarResponsive">
<ul class="navbar-nav ml-auto">
<li class="nav-item active">
<a class="nav-link" href="#">Home
<span class="sr-only">(current)</span>
</a>
</li>
<li class="nav-item">
<a class="nav-link" onclick="firebase.auth().signOut();" href="#">Sign Out</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">About</a>
</li>
</ul>
</div>
</div>
</nav>
<!-- Page Content -->
<div class="container">
<div class="row">
<div class="col-md-6 text-center">
<div class="input-group search">
<input id="searchText" class="form-control" placeholder="Where are you driving from?">
</div>
</div>
<div class="col-md-6 text-center">
<div class="input-group search">
<input id="searchText2" class="form-control" placeholder="Where are you going to?">
<button id="to" class="btn btn-outline-secondary" type="button" >
<i class="fa fa-map-marker black"></i>
</button>
</div>
</div>
</div>
<div class="row options">
<div class="col-md-3"> <button type="button" class="btn btn-warning text-center"> Gas <i class="fa fa-plug"></i> </button></div>
<div class="col-md-3"> <button type="button" class="btn btn-warning text-center"> Cafe <i class="fa fa-coffee"></i></button></div>
<div class="col-md-3"> <button type="button" class="btn btn-warning text-center"> ATM <i class="fa fa-money"></i></button></div>
<div class="col-md-3"> <button type="button" class="btn btn-warning text-center"> Acc <i class="fa fa-bed" aria-hidden='true'></i></button></div>
</div>
<div id = "map_container">
<div id ="map"></div>
<div id="googleMap" style="width:100%;height:400px;"><h1>Your Path is here ! </h1></div>
</div>
<form>
<select id="mySelect" size=2>
</select>
<button type="button" onclick="myFunction()">Choose</button>
</form>
<div id="TextBoxContainer">
<!--Textboxes will be added here -->
<div class="form-group">
<label for="usr">Choosen values</label>
<input type="text" class="form-control" id="usr">
</div>
</div>
<div class="row text-right options">
<div class="col-md-12"> <button type="button submit" class="btn btn-success" style="width:30%;" onClick="submitEver()" > Go </button></div>
</div>
</div>
<!-- Bootstrap core JavaScript -->
<script src="vendor/jquery/jquery.min.js"></script>
<script src="vendor/bootstrap/js/bootstrap.bundle.min.js"></script>
<script src="https://www.gstatic.com/firebasejs/4.9.0/firebase-app.js"></script>
<script src="https://www.gstatic.com/firebasejs/4.9.0/firebase-auth.js"></script>
<script src="https://www.gstatic.com/firebasejs/4.9.0/firebase-database.js"></script>
<script src="https://www.gstatic.com/firebasejs/4.9.0/firebase.js"></script>
<script>
var origin;
var destination;
var pathPointArray=[];
var map;
var infowindow;
var pointOfInterest;
var dictOfSuggestion = [];
var globalPlaceID;
var globalType;
var globalName;
var globalDic=[];
var count=1;
var numberOfStops;
var category=$('.btn-group > .btn.active').html();
//alert("category"+category);
var config = {
apiKey: "AIzaSyD30NRd2YYwkCS25FArj058_oUoXdPYp2I",
authDomain: "safecommutesbhacks2018.firebaseapp.com",
databaseURL: "https://safecommutesbhacks2018.firebaseio.com",
projectId: "safecommutesbhacks2018",
storageBucket: "safecommutesbhacks2018.appspot.com",
messagingSenderId: "178423802061",
};
firebase.initializeApp(config);
$( "#to" ).click(function() {
//alert($("#searchText").val());
origin=$("#searchText").val();
destination=$("#searchText2").val();
sbHackMap();
});
function writeDummyItinerary(userId) {
var usersRef = firebase.database().ref("users");
// even if itineraries doesnte xist yet, this will be ok. just write to the node and it will get created
var newItineraryRef = usersRef.child(userId).child("itineraries").push();
var newItineraryId = newItineraryRef.key;
newItineraryRef.set({
to: globalDic.to,
from: globalDic.from,
numStops: Math.ceil(numberOfStops),
jsonInfo: JSON.stringify(globalDic)
});
}
function submitEver(){
prompt("Final Json",JSON.stringify(globalDic));
document.getElementById("usr").value=JSON.stringify(globalDic);
writeDummyItinerary(1222);
}
function myFunction() {
var x = document.getElementById("mySelect").selectedIndex;
var y = document.getElementById("mySelect").options;
globalDic.to=destination;
globalDic.from=origin;
globalDic.push({
locationName: globalPlaceID,
type: "cafe",
placeName: y[x].text
});
//alert("Index: " + y[x].index + " is " + y[x].text);
}
function autoComp(){
var input = document.getElementById('searchText');
var options = {
types: ['(cities)'],
componentRestrictions: {country: 'us'}
};
autocomplete = new google.maps.places.Autocomplete(input, options);
var input2 = document.getElementById('searchText2');
var options2 = {
types: ['(cities)'],
componentRestrictions: {country: 'us'}
};
autocomplete = new google.maps.places.Autocomplete(input2, options2);
}
function sbHackMap() {
//This is mapProperties
//35.379701, -119.038609--Bkerfiel
//36.156525, -115.173636---Las Veg
var mapProp= {
center: pointOfInterest,//Make this dynamic eventually
zoom:17,
};
var directionsService = new google.maps.DirectionsService;
var directionsDisplay = new google.maps.DirectionsRenderer;
map=new google.maps.Map(document.getElementById("googleMap"),mapProp);
directionsDisplay.setMap(map);
infowindow = new google.maps.InfoWindow();
//document.getElementById('submit').addEventListener('click', function() { //Add Submit button later
//alert(origin);
calculateAndDisplayRoute(directionsService, directionsDisplay,origin,destination);
}
function calculateAndDisplayRoute(directionsService, directionsDisplay,or,des) {
directionsService.route({
origin: or,
destination: des,
travelMode: 'DRIVING'
}, function(response, status) {
if (status === 'OK') {
pathPointArray=[];
directionsDisplay.setDirections(response);
var hoursStrecth=2;
var time = response.routes[0].legs[0].duration.text;
//alert(time);
numberOfStops=(parseInt(time.split("hours")[0]*60)+parseInt((time.split("hours")[1]).split("mins")[0]))/(hoursStrecth*60);
//alert(numberOfStops);
var myRoute = response.routes[0].overview_path;
// /alert("No. Of routes availabe.."+myRoute.length+"...No. Of stops..."+Math.ceil(numberOfStops));
var incr=Math.floor(myRoute.length/(numberOfStops+1));
for (var i = incr; i < myRoute.length; i=i+incr) {
//alert(i);
pathPointArray.push(myRoute[i]);
createMarker(myRoute[i],0);
}
//fetchCheckPoints(time,pathPointArray);
} else {
window.alert('Directions request failed due to ' + status);
}
});
}
function callback(results, status) {
//alert("callback called.."+JSON.stringify(results)+"....."+status);
if (status == google.maps.places.PlacesServiceStatus.OK) {
//alert("ok");
dictOfSuggestion=[];
for (var i = 0; i < 10/*results.length*/; i++) {
//createMarker(results[i],1);
//
dictOfSuggestion.push(results[i]);
}
//prompt("dictOfSuggestion",JSON.stringify(dictOfSuggestion));
$("#mySelect").empty();
for (var i = 0; i < dictOfSuggestion.length; i++){
var txt=dictOfSuggestion[i].name;
var x = document.getElementById("mySelect");
var option = document.createElement("option");
option.text = txt ;
x.add(option);
}
/*for (var i = 0; i < dictOfSuggestion.length; i++){
var opt = dictOfSuggestion[i].name;
var li = document.createElement("li");
var link = document.createElement("a");
var text = document.createTextNode(opt);
link.appendChild(text);
link.href = "#";
li.appendChild(link);
list.appendChild(li);
}*/
////-----------------------------------------------//
//alert(JSON.stringify(dictOfSuggestion[0].photos[0].getUrl({'maxWidth': 35, 'maxHeight': 35})));
/*
for(var i=0 ; i< dictOfSuggestion.length ; i++) {
var photoUrl;
try{
photoURL=dictOfSuggestion[i].photos[0].getUrl({'maxWidth': 1000, 'maxHeight': 1000});
}
catch(err){
photoURL=dictOfSuggestion[0].photos[0].getUrl({'maxWidth': 1000, 'maxHeight': 1000});
}
$('<div class="item"><img src="'+photoURL+'"><div class="carousel-caption"></div> </div>').appendTo('.carousel-inner');
$('<li data-target="#carousel-example-generic" data-slide-to="'+i+'"></li>').appendTo('.carousel-indicators')
}
$('.item').first().addClass('active');
$('.carousel-indicators > li').first().addClass('active');
$('#carousel-example-generic').carousel();
////////////////---------
var x = document.getElementById("swipe_container");
x.style.display = "block";
//infowindow.setContent(place.name);
//infowindow.setContent(getWindowContent);
*/
infowindow.open(map, this);
}
}
//fiunction getWindowContent(){
//}
function displayLocation(latitude,longitude){
var request = new XMLHttpRequest();
var method = 'GET';
var url = 'http://maps.googleapis.com/maps/api/geocode/json?latlng='+latitude+','+longitude+'&sensor=true';
var async = true;
request.open(method, url, async);
request.onreadystatechange = function(){
if(request.readyState == 4 && request.status == 200){
var data = JSON.parse(request.responseText);
var address = data.results[0];
}
};
request.send();
};
function createMarker(place,key) {
var placeLoc;
var marker;
if(key==1){
placeLoc = place.geometry.location;
marker = new google.maps.Marker({
map: map,
position: place.geometry.location
});
}
else{
//alert(JSON.stringify(place));
placeLoc = place;
marker = new google.maps.Marker({
map: map,
position: place,
title: 'L'+count
});
count++;
}
//////CLICKINg///////////////////
marker.setMap(map);
google.maps.event.addListener(marker, 'click', function() {
//alert(marker.title);
globalPlaceID=marker.title;
//Sarre global yahan reset honge
dictOfSuggestion=[];
// alert("I am clicking something new..Dict shud be empty.."+dictOfSuggestion.length+"...I am clicking for.."+place);
fetchCheckPoints(place);
});
}
function fetchCheckPoints(place){
//alert("I am up for finding atm statations");
//var arrForLoc[]=pathPointArray;
//alert(arrForLoc);
//for (var i = 0; i < pathPointArray.length; i++) {
//alert("The lat and log for which I am searching stuff is ..."+place);
pointOfInterest=new google.maps.LatLng(place.lat(),place.lng());
var service = new google.maps.places.PlacesService(map);
service.nearbySearch({
location: pointOfInterest,
radius: 5000,
type: ['cafe']
}, callback);
//}
}
window.onload=function() {
firebase.auth().onAuthStateChanged(function(currentUser) {
if(currentUser) {
var currUserId=currentUser.uid;
console.log(currentUser);
} else {
window.location='login.html';
}
});
}
</script>
<!---This is the script for getting ggole api -->
<script src="https://maps.googleapis.com/maps/api/js?key=AIzaSyBv-DxoYSJV45J7rAz6-qCCv8HB2Wwqyp0&libraries=places&callback=autoComp"></script>
</body>
</html>