forked from easyacres/TestingCenterLocator
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathresults.js
More file actions
491 lines (452 loc) · 19.5 KB
/
results.js
File metadata and controls
491 lines (452 loc) · 19.5 KB
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
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
$(document).ready(function () {
var params = new URLSearchParams(window.location.search);
var zipCode = params.get("zip") //grab from url string
var stateCode = params.get("state") //grab from url string
$("#newSearchBtn").click(function (event) {
event.preventDefault();
zipCode = $("#resultsNewCity").val();
console.log(zipCode);
stateCode = $("#newStateList").val(); //Results page state select
console.log(stateCode);
runOurAPIs(zipCode, stateCode);
})
function runOurAPIs(zipCode, stateCode) {
//======================================================================
//covid stats API
//======================================================================
StatAPI = "e4d71997540c41028352933253eb7f8c";
console.log("Selected state: " + stateCode);
$.ajax({
type: "GET",
url: "https://api.smartable.ai/coronavirus/stats/US-" + stateCode,
// Request headers
beforeSend: function (xhrObj) {
xhrObj.setRequestHeader("Cache-Control", "no-cache");
xhrObj.setRequestHeader("Subscription-Key", StatAPI);
},
})
.then(function (data) {
confirmedCases = data.stats.totalConfirmedCases;
recoveredCases = data.stats.totalRecoveredCases;
totalDeaths = data.stats.totalDeaths;
$("#caseCount").text(confirmedCases);
$("#recoveryCount").text(recoveredCases);
$("#deathCount").text(totalDeaths);
console.log(confirmedCases, totalDeaths, confirmedCases);
console.log("Success: ", data);
})
//======================================================================
//google maps API
//======================================================================
// Google mapsAPI global vars
var map;
var service;
var currentLocation;
var geocoder = new google.maps.Geocoder();
var lat = '';
var lng = '';
var placeIDArray = [];
//Geocoder function
function getLatLngFromZip() {
//Convert entered zipcode into a latitude and longitude
geocoder.geocode({
'address': zipCode
}, function (results, status) {
if (status == google.maps.GeocoderStatus.OK) {
lat = results[0].geometry.location.lat();
lng = results[0].geometry.location.lng();
console.log("latitude: " + lat + " Longitude: " + lng);
initialize();
} else {
return;
}
});
}
function initialize() {
// Get current location from lat and long
$("#location-data-display").empty();
currentLocation = new google.maps.LatLng(lat, lng);
console.log(currentLocation);
// Display Map
map = new google.maps.Map(document.getElementById('map'), {
center: currentLocation,
zoom: 11.4,
disableDefaultUI: true,
// Map styling
styles: [{
"elementType": "geometry",
"stylers": [{
"color": "#1d2c4d"
}]
},
{
"elementType": "labels.text.fill",
"stylers": [{
"color": "#8ec3b9"
}]
},
{
"elementType": "labels.text.stroke",
"stylers": [{
"color": "#1a3646"
}]
},
{
"featureType": "administrative.country",
"elementType": "geometry.stroke",
"stylers": [{
"color": "#4b6878"
}]
},
{
"featureType": "administrative.land_parcel",
"elementType": "labels.text.fill",
"stylers": [{
"color": "#64779e"
}]
},
{
"featureType": "administrative.province",
"elementType": "geometry.stroke",
"stylers": [{
"color": "#4b6878"
}]
},
{
"featureType": "landscape.man_made",
"elementType": "geometry.stroke",
"stylers": [{
"color": "#334e87"
}]
},
{
"featureType": "landscape.natural",
"elementType": "geometry",
"stylers": [{
"color": "#023e58"
}]
},
{
"featureType": "poi",
"elementType": "geometry",
"stylers": [{
"color": "#283d6a"
}]
},
{
"featureType": "poi",
"elementType": "labels.text.fill",
"stylers": [{
"color": "#6f9ba5"
}]
},
{
"featureType": "poi",
"elementType": "labels.text.stroke",
"stylers": [{
"color": "#1d2c4d"
}]
},
{
"featureType": "poi.park",
"elementType": "geometry.fill",
"stylers": [{
"color": "#023e58"
}]
},
{
"featureType": "poi.park",
"elementType": "labels.text.fill",
"stylers": [{
"color": "#3C7680"
}]
},
{
"featureType": "road",
"elementType": "geometry",
"stylers": [{
"color": "#304a7d"
}]
},
{
"featureType": "road",
"elementType": "labels.text.fill",
"stylers": [{
"color": "#98a5be"
}]
},
{
"featureType": "road",
"elementType": "labels.text.stroke",
"stylers": [{
"color": "#1d2c4d"
}]
},
{
"featureType": "road.highway",
"elementType": "geometry",
"stylers": [{
"color": "#2c6675"
}]
},
{
"featureType": "road.highway",
"elementType": "geometry.stroke",
"stylers": [{
"color": "#255763"
}]
},
{
"featureType": "road.highway",
"elementType": "labels.text.fill",
"stylers": [{
"color": "#b0d5ce"
}]
},
{
"featureType": "road.highway",
"elementType": "labels.text.stroke",
"stylers": [{
"color": "#023e58"
}]
},
{
"featureType": "transit",
"elementType": "labels.text.fill",
"stylers": [{
"color": "#98a5be"
}]
},
{
"featureType": "transit",
"elementType": "labels.text.stroke",
"stylers": [{
"color": "#1d2c4d"
}]
},
{
"featureType": "transit.line",
"elementType": "geometry.fill",
"stylers": [{
"color": "#283d6a"
}]
},
{
"featureType": "transit.station",
"elementType": "geometry",
"stylers": [{
"color": "#3a4762"
}]
},
{
"featureType": "water",
"elementType": "geometry",
"stylers": [{
"color": "#0e1626"
}]
},
{
"featureType": "water",
"elementType": "labels.text.fill",
"stylers": [{
"color": "#4e6d70"
}]
}
]
});
// Request paramenters
var request = {
location: currentLocation,
openNow: true,
radius: '800',
query: 'COVID testing'
};
service = new google.maps.places.PlacesService(map);
service.textSearch(request, callback);
callback();
}
// Function for pulling Testing Centers
function callback(results, status) {
if (status == google.maps.places.PlacesServiceStatus.OK) {
console.log("Testing center Results: ", results);
//Loop that runs through our results
for (var i = 0; i < results.length; i++) {
var location = results[i];
// Push results to array
placeIDArray.push(location.place_id);
};
// Make our current location the first result
currentLocation = results[0].geometry.location;
// Set map center to first location
map.setCenter(results[0].geometry.location);
getLocationDetails();
};
};
// Function for getting out data
function getLocationDetails() {
placeIDArray.forEach(function (id) {
// For each place id we recive the following data
var request = {
placeId: id,
fields: ['name', 'address_component', 'geometry.location', 'rating', 'formatted_phone_number', 'photos', 'url', 'opening_hours', 'website', 'reviews'],
};
service = new google.maps.places.PlacesService(map);
service.getDetails(request, callback);
// This resturns our results
function callback(place, status) {
if (status == google.maps.places.PlacesServiceStatus.OK) {
console.log("location data: ", place);
// create our markers and display our location data
createMarker(place.geometry.location, place);
displayLocationData(place);
};
};
});
};
function displayLocationData(place) {
// Append the location data to the display
$("#location-data-display").append(`
<button class="accordion">
<h5 id="location-name">${place.name}</h5>
<i class="fas fa-map-marker-alt"></i><span id="address"<p id="address">
${place.address_components[0].long_name}
${place.address_components[1].short_name},
${place.address_components[2].long_name}
</p></span>
</button>
<div class="panel">
<i class="fas fa-phone-alt"></i><span id="phone-number><p id="phone-number">${place.formatted_phone_number}</p></span>
<i class="fas fa-map-marker-alt"></i><span id="full-address><p id="full-address">
${place.address_components[0].long_name}
${place.address_components[1].short_name},
${place.address_components[2].long_name},
${place.address_components[3].long_name},
${place.address_components[4].short_name},
${place.address_components[5].short_name}
</p></span>
<a id="directions" target="_blank" href="${place.url}">Get Directions</a>
<hr>
<p class="time"><i class="fas fa-clock"></i><span>${place.opening_hours.weekday_text[0]}</span></p>
<p class="time"><i class="fas fa-clock"></i><span>${place.opening_hours.weekday_text[1]}</span></p>
<p class="time"><i class="fas fa-clock"></i><span>${place.opening_hours.weekday_text[2]}</span></p>
<p class="time"><i class="fas fa-clock"></i><span>${place.opening_hours.weekday_text[3]}</span></p>
<p class="time"><i class="fas fa-clock"></i><span>${place.opening_hours.weekday_text[4]}</span></p>
<p class="time"><i class="fas fa-clock"></i><span>${place.opening_hours.weekday_text[5]}</span></p>
<p class="time"><i class="fas fa-clock"></i><span>${place.opening_hours.weekday_text[6]}</span></p>
<hr>
</div>
`);
};
function createMarker(position, location, label) {
// Marker parameters
var marker = new google.maps.Marker({
animation: google.maps.Animation.DROP,
position: position,
icon: {
url: "images/map-marker.png"
},
map: map
});
// Information to display when hovering over marker
var contentString = `
<div id="content">
<div id="siteNotice">
</div>
<h6 id="firstHeading" class="firstHeading">${location.name}</h6>
<hr>
<div id="bodyContent">
<p class="lead"> ${location.address_components[0].long_name} ${location.address_components[1].short_name}</h6>
<p class="lead"> ${location.address_components[2].long_name}, ${location.address_components[4].short_name}</h6>
<p class="lead"> ${location.address_components[6].long_name}</h6>
</div>
</div>`
const infowindow = new google.maps.InfoWindow({
content: contentString,
maxWidth: 500
});
// Have our markers display information when you hover over them
marker.addListener("mouseover", () => {
infowindow.open(map, marker);
});
marker.addListener('mouseout', () => {
infowindow.close();
});
};
//======================================================================
//News API
//======================================================================
function getArticles(event) {
var searchNewsCity = zipCode;
console.log(zipCode);
var assignedNewsArtCount = 5;
var assignedNewsContent = "COVID";
var assignedImage = "required";
// event.preventDefault();
console.log("searchNewsCity")
// console.log(searchNewsCity);
fetch("https://gnews.io/api/v3/search?q=" + assignedNewsContent + "&max=" + assignedNewsArtCount + "&image=" + assignedImage + "&token=e9869e383699068c951d662dbc54a452")
.then(function (response) {
return response.json();
})
.then(function (data) {
console.log(data);
var newsArticles = $("#newsArticles")
newsArticles.empty();
for (var i = 0; i < data.articles.length; i++) {
// var grabNewsTitle = data.articles[i].title;
// var grabNewsUrl = data.articles[i].url;
// var newNewsDiv = $("<div>").appendTo(newsArticles);
// $("<h3>").text(grabNewsTitle).appendTo(newNewsDiv);
// $("<p>").text(grabNewsUrl).appendTo(newNewsDiv);
var dateArray = data.articles[i].publishedAt.split(" ");
var dateElement = dateArray[0].split("-");
var finalDate = dateElement[1] + "-" + dateElement[2] + "-" + dateElement[0];
newsArticles.append(
`<div class="grid-x grid-margin-x">
<div class="large-6 cell">
<p><img src="${data.articles[i].image}"
alt="article image info ${data.articles[i].source.name, data.articles[i].title }" height="370" width="600"></p>
</div>
<div class="large-6 cell">
<h5><a href="${data.articles[i].url}">${data.articles[i].title}</a></h5>
<p>
<span><i class="fi-web "> ${data.articles[i].source.name} </i></span>
<br>
<span><i class="fi-calendar "> ${finalDate} </i></span>
</p>
<p>${data.articles[i].description}</p>
</div>
</div>
<hr>`
)
console.log(data.articles[i]);
}
//
});
}
getLatLngFromZip();
getArticles();
};
runOurAPIs(zipCode, stateCode);
function windowOnloadClickEvent (){
$(window).on("load", function () {
$("#loader-wrapper").fadeOut("slow");
$("body").removeClass("lock-screen");
// ==================================================================
$(".accordion").on("click", function () {
this.classList.toggle("active");
console.log("clicked");
var panel = this.nextElementSibling;
console.log("here", panel);
if (panel.style.display === "block") {
$(this).next().slideUp();
} else {
$(".panel").slideUp();
$(this).next().slideDown();
}
});
// ==================================================================
});
};
windowOnloadClickEvent ();
});