Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var x = document.getElementById("demo");
- var watchID = null;
- var counter = 0;
- function geo_success(position) {
- counter += 1;
- x.innerHTML = "Latitude: " + position.coords.latitude + ", Longitude: " + position.coords.longitude + ", Count: " + counter;
- }
- function geo_error() {
- x.innerHTML = "Sorry, no position available.";
- }
- var geo_options = {
- enableHighAccuracy: true,
- maximumAge: 30000,
- timeout: 27000
- };
- function toggleGeolocation() {
- if ("geolocation" in navigator) {
- if (watchID == null) {
- watchID = navigator.geolocation.watchPosition(geo_success, geo_error, geo_options);
- } else {
- navigator.geolocation.clearWatch(watchID);
- watchID = null;
- x.innerHTML = "Geolocation stopped.";
- }
- } else {
- x.innerHTML = "Geolocation is not supported by this browser.";
- }
- }
Add Comment
Please, Sign In to add comment