<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>
