I am getting a place name to this file using GET. Then I am converting the place name into latitude and longitude.
I want to display some data from the database, based on the latitude and longitude, but I am unable to send the latitude and longitude variables from JS to PHP.
I also tried Ajax, but that also didn't work, because PHP loads before the script. Correct me if I am wrong.
Any kind of help will be appreciated.
<?php
$user_latitude
$user_longitude
$result=$con->query("SELECT *, ( 6371 * acos( cos( radians($user_latitude) ) * cos( radians( lat ) ) * cos( radians( lon ) - radians($user_longitude) ) + sin( radians($user_latitude) ) * sin( radians( lat ) ) ) ) AS distance FROM Location HAVING distance < 100 ORDER BY distance LIMIT 0 , 10");
for($x=0;$x<$result->num_rows;$x++){
$row=$result->fetch_assoc();
echo "<div class='result-data'>";
echo $row["name"];
echo "</div>";
}
?>
<script>
$(function() {
geocoder = new google.maps.Geocoder();
alert($_GET('location'));
var address = $_GET('location');
address=address+',Delhi,India';
alert(address);
geocoder.geocode( { 'address': address}, function(results, status) {
if (status == google.maps.GeocoderStatus.OK) {
latitude=results[0].geometry.location.lat();
longituderesults[0].geometry.location.lng();
alert("Latitude: "+results[0].geometry.location.lat()+latitude);
alert("Longitude: "+results[0].geometry.location.lng()+longitude);
} else {
alert("Geocode was not successful for the following reason: " + status);
}
});
});
function $_GET(param) {
var vars = {};
window.location.href.replace(
/[?&]+([^=&]+)=?([^&]*)?/gi, // regexp
function( m, key, value ) { // callback
vars[key] = value !== undefined ? value : '';
}
);
if (param) {
return vars[param] ? vars[param] : null;
}
return vars;
}
</script>