开发者

iPhone and Android GPS coordinates in PHP

开发者 https://www.devze.com 2022-12-24 21:52 出处:网络
I\'m am curently doing an application wi开发者_开发问答th 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

I'm am curently doing an application wi开发者_开发问答th 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.


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
}
?>
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号