Geolocation Component - Reverse Geocoding

Adding reverse geocoding support to our component

HTML

<!DOCTYPE html>
<html>
  <head>
    <!-- Coded by Jason Mayes. Questions? Get in touch at: www.jasonmayes.com -->
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <meta name="author" content="Jason Mayes" />
	<meta name="description" content="HTML5 template" />
	<meta name="keywords" content="HTML5, template" />
    <title>HTML5 Template</title>
    <script type="text/javascript" src="//maps.googleapis.com/maps/api/js?sensor=false"></script>
  </head>
  <body>
    <h1>Geolocation Component - Reverse Geocoding - http://goo.gl/ksRu2</h1>
    <div id="geoResults"></div>
    <div id="map"></div>
  </body>
</html>

JavaScript

/**
 * @fileoverview A Geolocation component. Depends on Google Maps API.
 * @author Jason Mayes
 */
var geoComponent = function() {

  /**
   * The callback function upon receiving Geolocation data.
   */
  var geolocateCallbackFunction = null;

  /**
   * Store reference to the returned watchPosition geolocation object.
   * @type {integer}
   */
  var continuousReference = null;

  /**
   * Store reference to geocoder Google Maps object
   * @type {google.maps.Geocoder}
   */
  var geocoder = null;

  /**
   * Check if Geolocation is supported by the clients web browser.
   * @return {boolean} If the Geolocation object is available to use or not.
   */
  function isSupported() {
    if(window.navigator.geolocation) {
      return true;
    } else {
      return false;
    }
  }

  /**
   * Handle successful geolocation.
   */
  function geolocateSuccess(position) {
    geolocateCallbackFunction(position);
  }

  /**
   * Handle geolocation errors.
   */
  function geolocateError(error) {
    if (error.code === 1) {
      // User denied access to their location.
    }
    else if (error.code === 2) {
      // No position could be obtained.
    }
    else {
      // Request for location timed out.
    }
  }

  // Public properties.
  return {

    /**
     * Geolocate user.
     * @param {function} callback - Required: The function to call once 
     * geolocation complete.
     * @param {integer} maxAge - Optional parameter for the maximum time in
     * miliseconds we will allow to use a previously calculated location. This 
     * might improve speed in returning a result if we set this value higher as
     * the device wont need to re calculate its position.
     * @param {boolean} highAccuracy - If false we shall approximate user location
     * without using power hungry techniques such as GPS or WiFi. This is fast but 
     * can be inaccurate. If set to true it will try to use hardware on device to
     * better estimate position but this will take...