Created
February 13, 2020 02:10
-
-
Save samyok/b476bdfe8864eacf601d336fc805cc70 to your computer and use it in GitHub Desktop.
Locate Snow: https://irc.samyok.us
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"name": "locatesnow", | |
"version": "1.0.0", | |
"description": "", | |
"main": "server.js", | |
"scripts": { | |
"test": "echo \"Error: no test specified\" && exit 1", | |
"start": "node server.js" | |
}, | |
"keywords": [], | |
"author": "", | |
"license": "ISC", | |
"dependencies": { | |
"express": "^4.17.1", | |
"node-fetch": "^2.6.0", | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<html> | |
<head> | |
<title>LocateSnow</title> | |
<style> | |
/* Always set the map height explicitly to define the size of the div | |
* element that contains the map. */ | |
#map { | |
height: 100%; | |
} | |
/* Optional: Makes the sample page fill the window. */ | |
html, body { | |
height: 100%; | |
margin: 0; | |
padding: 0; | |
} | |
</style> | |
<link rel="stylesheet" href="https://unpkg.com/[email protected]/build/pure-min.css" | |
integrity="sha384-oAOxQR6DkCoMliIh8yFnu25d7Eq/PHS21PClpwjOTeU2jRSq11vu66rf90/cZr47" crossorigin="anonymous"> | |
<script src="https://code.jquery.com/jquery-3.4.1.min.js"></script> | |
</head> | |
<body> | |
<div id="map"></div> | |
<!-- Replace the value of the key parameter with your own API key. --> | |
<script src="https://maps.googleapis.com/maps/api/js?key=[[REDACTED]]&callback=initMap&libraries=places" async | |
defer></script> | |
<script> | |
var map; | |
function initMap() { | |
map = new google.maps.Map(document.getElementById('map'), { | |
center: { | |
lat: 44.3114, | |
lng: -96.7984 | |
}, | |
zoom: 10 | |
}); | |
var service = new google.maps.places.PlacesService(map); | |
$.get("https://s3.amazonaws.com/grayfilestore-ksfy/closingsData/closings_KSFY.json", data => { | |
data[0].record.forEach(record => { | |
if (record.forced_category_name === "Schools") { | |
$.get(`/map_location?search=${record.forced_organization_name}`, (searchData, status) => { | |
console.log(searchData); | |
new google.maps.Marker({ | |
position: searchData.candidates[0].geometry.location, | |
map: map, | |
label: record.forced_status_name | |
}); | |
}) | |
} | |
}) | |
}) | |
} | |
</script> | |
</body> | |
</html> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const GoogleMapsAPIKey = "[[REDACTED]]"; | |
const express = require('express'); | |
const app = express(); | |
app.listen(9090); | |
app.use(express.static('public')); | |
let fetch = require('node-fetch'); | |
let locations = {}; | |
app.get("/map_location", (req, res) => { | |
let searchQuery = req.query.search; | |
if (locations[searchQuery]) { | |
res.json(locations[searchQuery]) | |
} else { | |
fetch(`https://maps.googleapis.com/maps/api/place/findplacefromtext/json?input=${searchQuery}&inputtype=textquery&fields=geometry&key=${GoogleMapsAPIKey}`) | |
.then(response => response.json()) | |
.then(response => { | |
locations[searchQuery] = response; | |
res.json(response); | |
}); | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Move
public_index.html
topublic/index.html