Skip to content

Instantly share code, notes, and snippets.

@pawel-dubiel
Created September 13, 2012 14:26
Show Gist options
  • Save pawel-dubiel/3714643 to your computer and use it in GitHub Desktop.
Save pawel-dubiel/3714643 to your computer and use it in GitHub Desktop.
#Google #Maps #api constantly update user location on the map
/*global gmap */
function getUserLocation(map) {
if (navigator.geolocation) {
navigator.geolocation.getCurrentPosition(function (position) {
var point = new google.maps.LatLng(position.coords.latitude,
position.coords.longitude);
if (typeof getUserLocation.user_marker == 'undefined') {
getUserLocation.user_marker = new google.maps.Marker({
position:point,
map:gmap,
icon:'person.png'
});
getUserLocation.user_marker_window = new google.maps.InfoWindow({
content:'You'
});
google.maps.event.addListener(getUserLocation.user_marker, 'click', function () {
getUserLocation.user_marker_window.open(map, getUserLocation.user_marker);
});
}
getUserLocation.user_marker.setPosition(point);
});
}
}
if (navigator.geolocation) {
getUserLocation(gmap);
setInterval(function () {
getUserLocation(gmap);
}, 5000);
}
@asifsyed487
Copy link

How to use it in node.js file?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment