Hey guys I want the longitude and latitude I get from the javascript code to pass it to the php variables $lat and $lng so I can get the $city and use it in my sql query(query not included). Below is my code. Please help
<html>
<head>
<script>
function getLocation() {
if (navigator.geolocation) {
navigator.geolocation.getCurrentPosition(showPosition);
} else {
document.write("Geolocation is not supported by this browser.");
}
}
function showPosition(position) {
var latitude= position.coords.latitude;
var longitude= position.coords.longitude);
}
</script>
</head>
<body onload="getLocation()"></body>
</html>
<?php
function getaddress($lat,$lng)
{
$url = 'http://maps.googleapis.com/maps/api/geocode/json?latlng='.trim($lat).','.trim($lng).'&sensor=false';
$json = @file_get_contents($url);
$data=json_decode($json);
$status = $data->status;
if($status=="OK")
{
return $data->results[0]->formatted_address;
}
else
{
return false;
}
}
$lat= 33.568711799999996; //latitude
$lng= 35.3800354; //longitude
$address= getaddress($lat,$lng);
if($address)
{
// Delimiters may be slash, or comma
//$date = "04/30/1973";
list($address, $street, $city) = split('[,-]', $address);
echo "Address: $address; Street: $street; City: $city <br />\n";
}
else
{
echo "Not found";
}
?>