Support HTML5 geolocation for centering map
Fixes #12 by auto-centering map in the easiest way possible
This commit is contained in:
parent
acecc6d79b
commit
5e9196c8f3
18
gmap.html
18
gmap.html
@ -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() {
|
function initialize() {
|
||||||
var mapOptions = {
|
var mapOptions = {
|
||||||
center: new google.maps.LatLng(CenterLat, CenterLon),
|
center: new google.maps.LatLng(CenterLat, CenterLon),
|
||||||
@ -158,6 +173,9 @@
|
|||||||
};
|
};
|
||||||
Map = new google.maps.Map(document.getElementById("map_canvas"), mapOptions);
|
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. */
|
/* Setup our timer to poll from the server. */
|
||||||
window.setInterval(function() {
|
window.setInterval(function() {
|
||||||
fetchData();
|
fetchData();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user