daily pastebin goal
82%
SHARE
TWEET

Untitled

a guest Dec 15th, 2018 69 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.     <script>
  2.         var marker;
  3.         var infoWindow;
  4.         if (navigator.geolocation) {
  5.             var timeoutVal = 10 * 1000 * 1000;
  6.             navigator.geolocation.watchPosition(
  7.                 displayPosition,
  8.                 displayError,
  9.                 { enableHighAccuracy: true, timeout: timeoutVal, maximumAge: 0 }
  10.             );
  11.         }
  12.         else {
  13.             alert("Geolocation is not supported by this browser");
  14.         }
  15.         function displayPosition(position) {           
  16.             var pos = new google.maps.LatLng(position.coords.latitude, position.coords.longitude);
  17.             var options = {
  18.                 zoom: 10,
  19.                 center: pos,
  20.                 mapTypeId: google.maps.MapTypeId.ROADMAP
  21.             };
  22.             var map = new google.maps.Map(document.getElementById("map"), options);
  23.             // Remove the current marker, if there is one
  24.             if (typeof(marker) != "undefined") marker.setMap(null);
  25.             marker = new google.maps.Marker({
  26.                 position: pos,
  27.                 map: map,
  28.                 title: "User location"
  29.             });
  30.             var contentString = "<b>Timestamp:</b> " + parseTimestamp(position.timestamp) + "<br/><b>User location:</b> lat " + position.coords.latitude + ", long " + position.coords.longitude + ", accuracy " + position.coords.accuracy;
  31.             // Remove the current infoWindow, if there is one
  32.             if (typeof(infoWindow) != "undefined") infoWindow.setMap(null);
  33.             infowindow = new google.maps.InfoWindow({
  34.                 content: contentString
  35.             });
  36.             google.maps.event.addListener(marker, 'click', function() {
  37.                 infowindow.open(map,marker);
  38.             });
  39.         }
  40.         function displayError(error) {
  41.             var errors = {
  42.                 1: 'Permission denied',
  43.                 2: 'Position unavailable',
  44.                 3: 'Request timeout'
  45.             };
  46.             alert("Error: " + errors[error.code]);
  47.         }
  48.         function parseTimestamp(timestamp) {
  49.             var d = new Date(timestamp);
  50.             var day = d.getDate();
  51.             var month = d.getMonth() + 1;
  52.             var year = d.getFullYear();
  53.             var hour = d.getHours();
  54.             var mins = d.getMinutes();
  55.             var secs = d.getSeconds();
  56.             var msec = d.getMilliseconds();
  57.             return day + "." + month + "." + year + " " + hour + ":" + mins + ":" + secs + "," + msec;
  58.         }
  59.     </script>
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top