help me with this. I have a javascript to get current user coordinates (latitude & Longitude) by using a botton. So, what I want is when clicked
the button, it will get the coordinates
and display in the two input text
which is one for latitude and one for longitude. Before this, I just display it in <p>
element.
HTML & PHP:
<div class="mb-3"><input class="border rounded-0 form-control" type="text" name="business_latitude" id="" placeholder="Latitude" style="font-family: Roboto, sans-serif;" value="<?php echo $bizLat; ?>"></div>
<div class="mb-3"><input class="border rounded-0 form-control" type="text" name="business_longitude" id="" placeholder="Longitude" style="font-family: Roboto, sans-serif;" value="<?php echo $bizLong; ?>"></div>
<p id="lati"></p>
<p id="longi"></p>
Javascript:
var x = document.getElementById("lati");
var y = document.getElementById("longi");
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;
y.innerHTML ="Longitude: " + position.coords.longitude;
}
<?php echo $bizLat; ?>
, <?php echo $bizLong; ?>
here is where they get saved coordinates in database. I just want to edit the latitude and longitude by pressing the button.