iPhone and Android GPS coordinates in PHP
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
}
?>
精彩评论