I want to get the current GPS location from the user device and basically drop Lat and Long into the form fields. Then I can do everything by entering the location.
Below is the code for the alert popup I started working with. I want you to be able to click the button and fill in the long / lat in the form fields.
<html>
<head>
<script type="text/javascript">
function getLocationConstant()
{
if(navigator.geolocation)
{
navigator.geolocation.getCurrentPosition(onGeoSuccess,onGeoFormLat,on GeoFormLong,onGeoError);
} else {
alert("Your browser or device doesn't support Geolocation");
}
}
function onGeoSuccess(event)
{
alert(event.coords.latitude + ', ' + event.coords.longitude);
}
function onGeoFormLat(event)
{
var myVal;
myVal = document.getElementById(event.coords.latitude).value;
}
function onGeoFormLong(event)
{
var myVal;
myVal = document.getElementById(event.coords.longitude).value;
}
function onGeoError(event)
{
alert("Error code " + event.code + ". " + event.message);
}
function stopGetLocation(event)
{
navigator.geolocation.clearWatch(watchID);
}
</script>
</head>
<body>
<br><br>
Latitude: <input type="text" id="Latitude" name="onGeoFormLat" value="">
<br><br>
Longitude: <input type="text" id="Longitude" name="onGeoFormLong" value="">
<br>
<br><br><br>
<input type="button" value="Get Location" onclick="getLocationConstant()" />
<br><br>
</body>
</html>
source
share