-1

I have the following code:

<script type="text/javascript" src="../scripts/jquery-1.11.0.min.js"></script>
<script type="text/javascript">
var Location_lat;
var Location_lng;
function showMap(position) {
 Location_lat=position.coords.latitude;
 alert(Location_lat);
}
navigator.geolocation.getCurrentPosition(showMap);  
<?php
$Location_lat="<script>document.write(Location_lat)</script>"?>
</script> 
<?php echo  'php_'.$Location_lat;?>

When executed, the alert returns the good value but $Location_lat is undefined. Any help? Thanks

1 Answers1

1

If you don't need the value of coordinates on your server then simply display it using jquery or simple javascript. For example you can change your code to

<script type="text/javascript" src="../scripts/jquery-1.11.0.min.js"></script>
<script type="text/javascript">
var Location_lat;
var Location_lng;
function showMap(position) {
 Location_lat=position.coords.latitude;
 alert(Location_lat);
 $(body).append(Location_lat);
}
navigator.geolocation.getCurrentPosition(showMap);  

</script> 

And please avoid mixing server side script(php) with client side script (javascript). For that purpose learn AJAX

Taimour Tanveer
  • 408
  • 3
  • 11