<form class="HomePagePostcodeForm" id="HomePagePostcodeForm" method="POST" >
    <input type="hidden" name="form_submit_id" value="home_page_set_postcode" />

    <input type="hidden" name="geolocation_longitude" id="geolocation_longitude" value="0" />
    <input type="hidden" name="geolocation_latitude" id="geolocation_latitude" value="0" />

    <input type="text" name="set_postcode" placeholder="e.g. BS1 5UH" value="" />

    <input type="submit"  value="Search" />

    <input type="Button" onclick="GetGeolocation(); return false;" value="Use my location" />
  </form>


  <script>
    function GetGeolocation()
    {
      if (!navigator.geolocation)
      {
        alert('Geolocation is not supported by your browser.');
        return;
      }

      navigator.geolocation.getCurrentPosition(getCurrentPosition_Success, getCurrentPosition_Error);
      
      function getCurrentPosition_Success (position)
      {
        //Success
        document.getElementById('geolocation_longitude').value = position.coords.longitude;
        document.getElementById('geolocation_latitude').value = position.coords.latitude;

        //Submit the form
        document.getElementById('HomePagePostcodeForm').submit();
      }
      
      function getCurrentPosition_Error (error)
      {
        alert('Unable to retrieve your location. Reason: ' + error.message);
      }
    }
  </script>
USEFUL?
We benefit hugely from resources on the web so we decided we should try and give back some of our knowledge and resources to the community by opening up many of our company’s internal notes and libraries through mini sites like this. We hope you find the site helpful.
Please feel free to comment if you can add help to this page or point out issues and solutions you have found, but please note that we do not provide support on this site. If you need help with a problem please use one of the many online forums.

Comments

Your email address will not be published. Required fields are marked *