Preview

13 - JavaScript and Geolocation

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

  FALSE

  TRUE

 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

  FALSE

  TRUE

 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>

  FALSE

  TRUE

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

  showPosition()

  getLatitude()

  getCurrentPosition()

  x.innerHtml

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

  the national archive of maps (in the British Library)

  mappit.com

  a physical map book

  Google maps

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

  Up-to-date local information

  Showing Points-of-interest near the user

  All of the listed options are valid

  Turn-by-turn navigation (GPS)

 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>

  clearWatch()

  watchPosition()

  coords.altitudeAccuracy

  coords.heading

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

  variable

  function

  external script

  parameter

 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

  external scripts

  properties

  variables

  functions