I want to post the value of name,latitude,longitude and the phone number in php.I am using html as front end to collect the details.I am unable to post the latitude and longitude in php but i can post the name,phone number.How to post the latitude and longitude of my location in php?
<html>
<body>
<form method="post" action="try2.php">
First name:<input type="text" name="first_name" ><br>
Phone:<input type="tel" name="phone" >
<p><button onclick="geoFindMe()">Show my location</button></p>
<div id="out"></div>
<script>
function geoFindMe() {
var output = document.getElementById("out");
if (!navigator.geolocation){
output.innerHTML = "<p>Geolocation is not supported by your
browser</p>";
return;
}
function success(position) {
var latitude = position.coords.latitude;
var longitude = position.coords.longitude;
output.innerHTML = '<p>Latitude is ' + latitude + '° <br>Longitude is ' + longitude + '°</p>';
var img = new Image();
img.src = "https://maps.googleapis.com/maps/api/staticmap?center=" +
latitude + "," + longitude + "&zoom=13&size=300x300&sensor=false";
output.appendChild(img);
}
function error() {
output.innerHTML = "Unable to retrieve your location";
}
output.innerHTML = "<p>Locating…</p>";
navigator.geolocation.getCurrentPosition(success, error);
}
</script>
<input type="submit" value="submit" required>
</form>
Php code:
<?php
$first_name=$_POST["first_name"];
$longitude=$_POST["longitude"];
$latitude=$_POST["latitude"]
$phone=$_POST["phone"];
echo "$latitude";
?>