Bonjour,

Je vous expose le problème : j'aimerais enregistrer la position gps ( et si possible la boussole ) d'un iPhone, sur mon ordinateur, le tout dans un fichier gps.txt ( par exemple )

Pour passer une variable JS vers le script PHP, j'utilise le code suivant ( pas de moi ) :
Page principale ( index.html) :
Code html : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width; initial-scale=1.0; maximum-scale=1.0;">
 
 
 
 
</head>
 
 
 
<script type="text/javascript">
 
width = screen.width;
height = screen.height;
 
if (width > 0 && height >0) {
    window.location.href = "/html/main.php?width=" + width + "&height=" + height;
} else 
    exit();
 
</script>
 
</html>

Script PHP ( main.php) :
Code php : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
<?php
echo "<h1>Screen Resolution:</h1>";
echo "Width  : ".$_GET['width']."<br>";
echo "Height : ".$_GET['height']."<br>";
?>

Et en temps "normal", j'utilise ce code pour afficher la position GPS ( lat, long, etc ... ) :

Code html : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width; initial-scale=1.0; maximum-scale=1.0;">
 
 
 
<style type="text/css">
@font-face {
font-family: "arial";
src: url(arial.ttf) format("truetype");
}
</style>
  <script type="text/javascript">
 
    function startWatch(){
      if (navigator.geolocation)
        var watchId = navigator.geolocation.watchPosition(successCallback,
                                  errorCallback,
                                  {enableHighAccuracy:true,
                                  timeout:10000,
                                  maximumAge:0});
      else
        alert("Votre navigateur ne prend pas en compte la géolocalisation HTML5");
    }
 
    function stopWatch(){
      navigator.geolocation.clearWatch(watchId);
    }     
 
    function successCallback(position){
      document.getElementById("lat").innerHTML = position.coords.latitude;
      document.getElementById("long").innerHTML = position.coords.longitude;
      document.getElementById("prec").innerHTML = position.coords.accuracy;
      document.getElementById("alt").innerHTML = position.coords.altitude;
      document.getElementById("precalt").innerHTML = position.coords.altitudeAccuracy;
      document.getElementById("angle").innerHTML = position.coords.heading;
      document.getElementById("speed").innerHTML = position.coords.speed;
      document.getElementById("time").innerHTML = new Date(position.timestamp);
    };  
 
    function errorCallback(error){
      switch(error.code){
        case error.PERMISSION_DENIED:
          alert("L'utilisateur n'a pas autorisé l'accès à sa position");
          break;
        case error.POSITION_UNAVAILABLE:
          alert("L'emplacement de l'utilisateur n'a pas pu être déterminé");
          break;
        case error.TIMEOUT:
          alert("Le service n'a pas répondu à temps");
          break;
        }
    };
 
  </script>
</head>
 
<body>
   <p><FONT face="arial" color="red"><span id="lat"></span></FONT>Latitude :  </p>
    <p><FONT  face="arial" color="red"><span id="long"></span></FONT>Longitude : </p>
    <p><FONT  face="arial" color="red"><span id="prec"></span></FONT>Précision : </p>
    <p><FONT  face="arial" color="red"><span id="alt"></span></FONT>Altitude : </p>
    <p><FONT  face="arial" color="red"><span id="precalt"></span></FONT>Précision altitude : </p>
 
<body onload="startWatch();">
</body>
</html>

Et ma question est donc : comment pourrais-je donc bien faire pour, à la place de la résolution ( et donc possiblement l'enregistrer dans un gps.txt a la'ide du PHP, ça je sais faire ), faire passer les variables du GPS ?

J'ai déjà tenté de remplacer le "screen.width" par "position.coords.latitude", mais malheureusement, cela ne marche pas ... ( pas de demande d'utilisation de données GPS, ni de redirection vers le main.php )

Si jamais vous avez une idée, ou une solution toute autre ( ajax ou quoi que ce soit qui soit supporté par le iPhone ), je suis preneur.

Merci de votre attention =)