Support HTML5 geolocation for centering map

Fixes #12 by auto-centering map in the easiest way possible
This commit is contained in:
Yuval Adam 2013-06-09 15:52:42 +03:00
parent acecc6d79b
commit 5e9196c8f3

View File

@ -150,6 +150,21 @@
});
}
function center_by_geolocation() {
if (navigator.geolocation) {
navigator.geolocation.getCurrentPosition(function(pos){
Map.setCenter(new google.maps.LatLng(
pos.coords.latitude, pos.coords.longitude
));
}, function() {
console.log('Geolocation error');
});
}
else {
console.log('Geolocation not supported')
}
}
function initialize() {
var mapOptions = {
center: new google.maps.LatLng(CenterLat, CenterLon),
@ -158,6 +173,9 @@
};
Map = new google.maps.Map(document.getElementById("map_canvas"), mapOptions);
/* Set center by geolocation if browser supports it */
center_by_geolocation();
/* Setup our timer to poll from the server. */
window.setInterval(function() {
fetchData();