-
-
Save stephenlb/b1ce5952bc3d550568f699bcb90b9b67 to your computer and use it in GitHub Desktop.
This file contains 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
<script src="https://cdn.pubnub.com/sdk/javascript/pubnub.4.17.0.js"></script> | |
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script> | |
<script src="https://maps.googleapis.com/maps/api/js?v=3.exp"></script> |
This file contains 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
that.json_data = file; // the original json object | |
that.formatted_json = formatJSON(that.json_data); // formatted json for simplicity | |
that.hash_table = extractHash(that.formatted_json); // coordinates encoded as hash strings |
This file contains 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
function formatJSON(json) { | |
var stations = json.root.stations[0].station; | |
var stations_formatted = []; | |
stations.forEach(function(station) { | |
var lat = station.gtfs_latitude[0]; | |
var lng = station.gtfs_longitude[0]; | |
var name = station.name[0]; | |
var abbr = station.abbr[0]; | |
new_station = {"lat": lat,"lng": lng,"name": name, "abbr": abbr}; | |
stations_formatted.push(new_station); | |
}); | |
return stations_formatted; | |
} |
This file contains 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
function extractHash(formatted_json) { | |
var hash_table = []; | |
formatted_json.forEach(function(station) { | |
geohash_string = geoToHash(station.lat,station.lng); | |
hash_table.push(geohash_string); | |
}); | |
return hash_table; | |
} |
This file contains 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
function geoToHash(lat,lng) { | |
return ngeohash.encode(lat,lng,4); | |
} |
This file contains 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
function hashMatching(user_hash, hash_table) { | |
var matches = []; | |
hash_table.forEach(function(value,i) { | |
var value_hash = value.substring(0,6); | |
if (value_hash === user_hash) { | |
value_object = {"hash": value_hash, "index": i}; | |
matches.push(value_object); | |
} | |
}); | |
return matches; | |
} |
This file contains 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
if (navigator.geolocation) { | |
navigator.geolocation.getCurrentPosition(function(position) { | |
… |
This file contains 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
that.lat = 37.6; | |
that.lng = -122.4; | |
var lat = that.lat; | |
var lng = that.lng; |
This file contains 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
var app = require("./app.js"); |
This file contains 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
var json_data, hash_table, hash_matches, destinations; | |
… | |
json_data_formatted = app.formatted_json; | |
hash_table = app.hash_table; | |
hash_matches = app.hash_matches; | |
destinations = app.destinations; |
This file contains 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
pubs(); | |
google.maps.event.addDomListener(window, 'load', initialize()); |
This file contains 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
<script src="bundle.js"></script> |
This file contains 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
function pubs() { | |
pubnub = new PubNub({ | |
publishKey : 'demo', | |
subscribeKey : 'demo' | |
}) |
This file contains 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
var business_marker = new google.maps.Marker({position: {lat: match_lat, lng: match_lng}, map: map}); | |
business_marker.setMap(map); |
This file contains 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
google.maps.event.addListener(business_marker, 'mouseover', function() { | |
infowindow.open(map,business_marker); | |
}); | |
google.maps.event.addListener(business_marker, 'mouseout', function() { | |
infowindow.close(map,business_marker); |
This file contains 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
$.ajax({ | |
type: "GET", | |
url: "data/MLBR.json", | |
dataType: "json", | |
success: function(file) { | |
main_two(file); | |
} | |
}); |
This file contains 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
|- station | |
|- Object | |
|- etd | |
|- Object (Destinations) | |
|- estimate | |
|- trains | |
|- minutes until departure, or “Leaving” |
This file contains 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
var etd = json.root.station[0].etd; | |
that.destinations = []; | |
var times = []; | |
etd.forEach(function(destination) { | |
var abbr = destination.abbreviation[0]; | |
var dest = destination.destination[0]; | |
var est = destination.estimate; | |
est.forEach(function(estimate) { | |
var min = estimate.minutes[0]; | |
times.push(min); | |
}); | |
that.destinations.push({"destination": dest, "abbreviation": abbr, "times": times}); | |
}); |
This file contains 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
var times = destination.times; | |
dest_string = dest_string + "<p><i>" + destination.abbreviation + ":" + "</i><p>"; | |
times.forEach(function(time) { | |
dest_string = dest_string + " " + time; | |
}); |
This file contains 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
var infowindow = new google.maps.InfoWindow({ | |
content: "<b>" + BusinessName + "</b>" + | |
"<p>" + dest_string + "</p></p></p>" | |
}); |
This file contains 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
browserify js/app.js -o bundle.js |
This file contains 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
var xml2js = require('xml2js'), | |
fs = require('fs'), | |
path = require('path'), | |
request = require('request'); |
This file contains 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
request("http://api.bart.gov/api/stn.aspx?cmd=stns", function(error, response, body) { | |
// do something with response body here | |
}); |
This file contains 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
function parseData(data) { | |
... | |
} |
This file contains 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
var parseString = xml2js.parseString; | |
parseString(data, function(err, result) { | |
string_result = JSON.stringify(result); | |
} |
This file contains 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
fs.writeFile(path.join(__dirname, '../','data/allstations.json'), string_result, function(err) { | |
… |
This file contains 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
$(document).ready(function() { | |
$.ajax({ | |
type: "GET", | |
url: "data/allstations.json", | |
dataType: "json", | |
success: function(file) { | |
main(file); | |
} | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment