Advertisement
Guest User

Untitled

a guest
Jul 23rd, 2014
200
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.   var locationElement = document.getElementById("location-element");
  2.  
  3.         function visualizeGeolocation(imageCreationFunction) {
  4.             navigator.geolocation.getCurrentPosition(
  5.                 function (position) {
  6.                     parseLatAndLongCoords(position, imageCreationFunction,
  7.                         function (errorMessage) {
  8.                             console.log("Could not parse coords: " + errorMessage);
  9.                         });
  10.                 },
  11.                 function (error) {
  12.                     console.log("Could not access geolocation: " + error);
  13.                 });
  14.         }
  15.  
  16.         function parseLatAndLongCoords(geolocationPosition, success, error) {
  17.             if (geolocationPosition.coords) {
  18.                 var latAndLong = { lat: geolocationPosition.coords.latitude, long: geolocationPosition.coords.longitude };
  19.                 success(latAndLong);
  20.             }
  21.             else {
  22.                 error("Could not fing coords object. Are you sure you are passing a navigator.geolocation.getCurrentPosition result?");
  23.             }
  24.         }
  25.  
  26.         function createGeolocationImage(coordsObj) {
  27.             var imgElement = document.createElement("img");
  28.  
  29.             var imgSrc = "http://maps.googleapis.com/maps/api/staticmap?center=" + coordsObj.lat + "," + coordsObj.long + "&zoom=13&size=500x500&sensor=false";
  30.  
  31.             imgElement.setAttribute("src", imgSrc);
  32.  
  33.             locationElement.appendChild(imgElement);
  34.         }
  35.  
  36.         visualizeGeolocation(createGeolocationImage);
  37.  
  38.         setInterval(function () {
  39.             var currentDateTime = new Date();
  40.             document.getElementById("clock").innerHTML = currentDateTime.getHours() + ":" + currentDateTime.getMinutes() + ":" + currentDateTime.getSeconds();
  41.         }, 1000);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement