I am trying to pass the results of position.coords.latitude
and position.coords.longitude
into the values of "lat" and "lng" on the form, but I have no idea how?
<button onclick="getLocation()">Get Geo Location</button>
<p id="getGeo"></p>
<script>
var x = document.getElementById("getGeo");
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>
<form action="insert.php" method="post">
<label id="id">Location name:</label><br/>
<input type="text" name="id"><br/>
<label id="lat">Latitude:</label><br/>
<input type="text" name="lat" value="WHAT HERE??"><br/>
<label id="lng">Longitude:</label><br/>
<input type="text" name="lng" value="WHAT HERE??"><br/>
<label id="updated">Updated:</label><br/>
<input type="date" name="updated"><br/>
<br>
<button type="submit" name="save">Insert new record</button>
</form>