Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@oalami
Last active March 12, 2021 13:27
Show Gist options
  • Star 6 You must be signed in to star a gist
  • Fork 4 You must be signed in to fork a gist
  • Save oalami/d61718d47266bd521228 to your computer and use it in GitHub Desktop.
Save oalami/d61718d47266bd521228 to your computer and use it in GitHub Desktop.
Global Earthquakes in Realtime using Firebase Open Data Sets
const CONTINENTS = ["europe", "asia", "africa", "north_america", "south_america", "antartica", "oceanic"];
var map;
var previousInfowindow;
var ref = new Firebase("https://publicdata-earthquakes.firebaseio.com/by_continent/");
function mapQuake(snapshot) {
var quake = snapshot.val();
var myLatlng = new google.maps.LatLng(quake.location.lat,quake.location.lng);
map.setCenter(myLatlng);
var marker = new google.maps.Marker({
position: myLatlng,
map: map,
animation: google.maps.Animation.DROP,
});
google.maps.event.addListener(marker, 'click', function() {
infowindow = new google.maps.InfoWindow({
content: '<b>Magnitude: </b>' + quake.mag + '<br /><b>Where:</b> '+ quake.place + '<br /><b>When: </b>' + (new Date(quake.time))
});
if (previousInfowindow) {
previousInfowindow.close();
}
infowindow.open(map,marker);
previousInfowindow = infowindow;
});
}
function start() {
map = new google.maps.Map(document.getElementById('map_canvas'), {zoom: 3});
for (var con=0; con<CONTINENTS.length; con++) {
var continent = CONTINENTS[con];
for (var mag=0; mag<10; mag++) {
var magRef = ref.child(continent).child(mag.toString());
magRef.orderByKey().limitToLast(3).on("child_added", mapQuake);
}
}
}
$(start);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment