Preview

13 - JavaScript and Geolocation

 1. The HTML Geolocation API is used to locate a user's position

  TRUE

  FALSE

 2. Since ascertaining geolocation of a user is hugely useful, the position is available to all developers and websites, even without user approval

  FALSE

  TRUE

 3. The getCurrentPosition() method is used to return the user's position

  TRUE

  FALSE

 4. This example returns the latitude and longtitude of the user's position
<script>
var x = document.getElementById("demo");
function getLocation() {
  if (navigator.geolocation) {
    navigator.geolocation.getCurrentPosition(showPosition);
  } else {
    x.innerHTML = "Geolocation is not supported by this browser.";
  }
}

function showPosition(position) {
  x.innerHTML = "Latitude: " + position.coords.latitude + 
  "<br>Longitude: " + position.coords.longitude; 
}
</script>

  TRUE

  FALSE

 5. In the above code which function is run, only if Geolocation is supported?

  x.innerHtml

  getLatitude()

  showPosition()

  getCurrentPosition()

 6. To display the result in a map, you need access to a map service, like ___________

  Google maps

  mappit.com

  a physical map book

  the national archive of maps (in the British Library)

 7. Geolocation is also very useful for location-specific information, like:

  Showing Points-of-interest near the user

  Turn-by-turn navigation (GPS)

  Up-to-date local information

  All of the listed options are valid

 8. Returns the current position of the user and continues to return updated position as the user moves (like the GPS in a car).
<script>
var x = document.getElementById("demo");
function getLocation() {
  if (navigator.geolocation) {
    navigator.geolocation.watchPosition(showPosition);
  } else {
    x.innerHTML = "Geolocation is not supported by this browser.";
  }
}
function showPosition(position) {
  x.innerHTML = "Latitude: " + position.coords.latitude + 
  "<br>Longitude: " + position.coords.longitude; 
}
</script>

  coords.heading

  coords.altitudeAccuracy

  clearWatch()

  watchPosition()

 9. The location argument is usually a _________. getCurrentPosition then provides some position values for you to manipulate

  parameter

  external script

  function

  variable

 10. "cords" is one of the __________ returned by the getCurrentPosition method (the other one is timestamp).
After a dot, you can type one of quite a few other sub-properties.
 We used latitude. 

But here are the other options

longitude
accuracy
altitude
altitudeAccuracy
heading
speed

  variables

  properties

  external scripts

  functions