tags:

views:

341

answers:

1

Hello everyone,

I'm am curently doing an application with Google Maps, where I am checking the position of the user with the javascript API, but I would like to know if there is a way to check the GPS variables in a PHP file ?

Some kind of GET parameter, but it seems nothing like that exists.

A: 

I'm not familiar with the API, but if you have a javascript one, and that's it, you would have to have something with the Javascript pass the information back to the server for the PHP backend to use. PHP, and any other server-side scripting language, cannot access anything from the client, other than what is passed in the HTTP headers when it does a page request.

The easiest thing to do would be to have a page the user has to hit first, with the bit of JS picking up the coordinates, then form a URL (ie: http://my.location/index.php?lat=12.45&long=67.89) and redirect to that. This would happen as soon as the user visits.

<?php
if (!isset($_GET['long']) && !isset($_GET['lat'])) {
    ?>
    <source type='text/javascript'>
        // Do the redirect here
    </source>
    <?php
} else {
    $latitude = $_GET['latitude'];
    $longitude = $_GET['longitude'];
?>
<!-- All your HTML, logic, etc. goes here -->
<?php
}
?>
Slokun
Yes, but my main problem is that I don't want them to "cheat" and pass false GPS coordinates, which is pretty easy in Javascript.I guess I will have to check the coordinates every minute and stock it somewhere server side to see if they are not jumping around.
rnaud