IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

APIs Google Discussion :

Afficher une position sur google map à partir des coordonnées gps saisies [Google Maps]


Sujet :

APIs Google

  1. #1
    Membre régulier
    Femme Profil pro
    Développeur Web
    Inscrit en
    Octobre 2010
    Messages
    414
    Détails du profil
    Informations personnelles :
    Sexe : Femme
    Localisation : France, Seine Maritime (Haute Normandie)

    Informations professionnelles :
    Activité : Développeur Web

    Informations forums :
    Inscription : Octobre 2010
    Messages : 414
    Points : 111
    Points
    111
    Par défaut Afficher une position sur google map à partir des coordonnées gps saisies
    Bonjour
    J'aimerais marquer sur ma carte la position d'un point à partir des coordonnées GPS que j'ai saisi dans un formulaire. En effet j'ai un formulaire avec 2 champs (Latitude et Longitude) et un bouton. Je cherche comment récupérer la valeur des champs et les positionner sur la carte.
    Voici mon code :
    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
    <!DOCTYPE html>
    <html>
      <head>
        <title>Simple Map</title>
        <meta name="viewport" content="initial-scale=1.0">
        <meta charset="utf-8">
        <style>
          /* Always set the map height explicitly to define the size of the div
           * element that contains the map. */
          * #map {
           * height: 70%;
         * }
         */
         
          /* Optional: Makes the sample page fill the window. */
          html, body {
            height: 100%;
            margin: 0;
            padding: 0;
          }
        </style>
      </head>
      <body>
      <br/><br/>
      <form border="2">
      <input type="text" id="latitude" placeholder="Latitude" />
      <input type="text" id="longitude" placeholder="Longitude" />
      <br/><br/>
      <input type="submit"  name="envoyer" value="Localiser sur Google Map" onclick="TrouverCoordGPS();"/>
      </form>
      <br/><br/>
        <span id="text_latlng"></span>
        <div id="map-canvas" style="float:right;height:220px;width:45%"></div>
        <script type="text/javascript">
          var geocoder;
          var map;
          function initMap() {
            geocoder = new google.maps.Geocoder();
           
            // Ici j'ai mis la latitude et longitude de Paris pour centrer la carte de départ
            var latlng = new google.maps.LatLng(48.866667,2.333333);
            var mapOptions = {
                zoom      : 14,
                center    : latlng,
                mapTypeId : google.maps.MapTypeId.ROADMAP
            }
           
            // map-canvas est le conteneur HTML de la carte Google Map
            map = new google.maps.Map(document.getElementById('map-canvas'), mapOptions);
        }
       
            // Création du marqueur du lieu (épingle)
          var marker = new google.maps.Marker({
              map: map,
              position: results[0].geometry.location
          });
        } else {
          alert('Coordonnées GPS introuvable: ' + status);
        }
      });
          }
        </script>
        <script src="https://maps.googleapis.com/maps/api/js?key=maclefxxxxxxxxxxamoi&callback=initMap"
        async defer></script>
      </body>
    </html>
    Formatrice - Web développeuse - WebMarketing - Recrutement
    Site O'ClockWeb : http://oclockweb.cvflashjob.com/
    Mon Facebook : https://www.facebook.com/minkoueobame

  2. #2
    Membre régulier
    Femme Profil pro
    Développeur Web
    Inscrit en
    Octobre 2010
    Messages
    414
    Détails du profil
    Informations personnelles :
    Sexe : Femme
    Localisation : France, Seine Maritime (Haute Normandie)

    Informations professionnelles :
    Activité : Développeur Web

    Informations forums :
    Inscription : Octobre 2010
    Messages : 414
    Points : 111
    Points
    111
    Par défaut
    J'ai essayé de le faire en PHP mais ça ne marche pas :

    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
    <?php
    // On vérifie si la variable existe et sinon elle vaut NULL
    $latitude = isset($_POST['latitude']) ? $_POST['latitude'] : NULL;
    $longitude = isset($_POST['longitude']) ? $_POST['longitude'] : NULL;
    ?>
     
    <!DOCTYPE html>
    <html>
      <head>
        <title>Simple Map</title>
        <meta name="viewport" content="initial-scale=1.0">
        <meta charset="utf-8">
        <style>
          /* Always set the map height explicitly to define the size of the div
           * element that contains the map. */
          #map {
            height: 70%;
          }
          /* Optional: Makes the sample page fill the window. */
          html, body {
            height: 100%;
            margin: 0;
            padding: 0;
          }
        </style>
      </head>
      <body>
      <br/><br/>
      <form name="carte" action="affichMap.php" method="POST">
      <input type="text" name="latitude" placeholder="Latitude" />
      <input type="text" name="longitude" placeholder="Longitude" />
      <br/><br/>
      <input type="submit"  name="envoyer" value="Envoyer"/>
      </form>
      <br/><br/>
        <div id="map"></div>
        <script>
          var map;
              var latitude = '<?php echo $latitude; ?>' ;
              var longitude = '<?php echo $longitude; ?>' ;
          function initMap() {
                var uluru= {lat:latitude, lng: longitude};
            var map = new google.maps.Map(document.getElementById('map'), {
              zoom: 14,
                      center:uluru
            });
                    var marker = new google.maps.Marker({
              position: uluru,
              map: map
            });
          }
        </script>
        <script src="https://maps.googleapis.com/maps/api/js?key=maclefxxxxxxxxxxamoi&callback=initMap"
        async defer></script>
      </body>
    </html>
    Formatrice - Web développeuse - WebMarketing - Recrutement
    Site O'ClockWeb : http://oclockweb.cvflashjob.com/
    Mon Facebook : https://www.facebook.com/minkoueobame

  3. #3
    Membre régulier
    Femme Profil pro
    Développeur Web
    Inscrit en
    Octobre 2010
    Messages
    414
    Détails du profil
    Informations personnelles :
    Sexe : Femme
    Localisation : France, Seine Maritime (Haute Normandie)

    Informations professionnelles :
    Activité : Développeur Web

    Informations forums :
    Inscription : Octobre 2010
    Messages : 414
    Points : 111
    Points
    111
    Par défaut
    Ca marche avec ce code :

    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
    <?php
    // On vérifie si la variable existe et sinon elle vaut NULL
    $latitude = isset($_POST['latitude']) ? $_POST['latitude'] : NULL;
    $longitude = isset($_POST['longitude']) ? $_POST['longitude'] : NULL;
    ?>
     
    <!DOCTYPE html>
    <html>
      <head>
        <title>Simple Map</title>
        <meta name="viewport" content="initial-scale=1.0">
        <meta charset="utf-8">
        <style>
          /* Always set the map height explicitly to define the size of the div
           * element that contains the map. */
          #map {
            height: 70%;
          }
          /* Optional: Makes the sample page fill the window. */
          html, body {
            height: 100%;
            margin: 0;
            padding: 0;
          }
        </style>
      </head>
      <body>
      <br/><br/>
      <form name="carte" action="affichMap.php" method="POST">
      <input type="text" name="latitude" placeholder="Latitude" />
      <input type="text" name="longitude" placeholder="Longitude" />
      <br/><br/>
      <input type="submit"  name="envoyer" value="Localiser sur Google Map" onclick="initMap();"/>
      </form>
      <br/><br/>
        <div id="map"></div>
        <script type="text/javascript">
          var map;
              var latitude = <?php echo $latitude; ?> ;
              var longitude = <?php echo $longitude; ?> ;
          function initMap() {
                 var uluru= {lat: latitude, lng: longitude};
            var map = new google.maps.Map(document.getElementById('map'), {
              zoom: 14,
                      center:uluru
            });
                    var marker = new google.maps.Marker({
              position: uluru,
              map: map
            });
          }
        </script>
        <script src="https://maps.googleapis.com/maps/api/js?key=maclefxxxxxxxxxxamoi&callback=initMap"
        async defer></script>
      </body>
    </html>
    Formatrice - Web développeuse - WebMarketing - Recrutement
    Site O'ClockWeb : http://oclockweb.cvflashjob.com/
    Mon Facebook : https://www.facebook.com/minkoueobame

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. Afficher une image sur un formulaire à partir d'une base de données
    Par abiking dans le forum VB 6 et antérieur
    Réponses: 8
    Dernier message: 07/12/2015, 21h56
  2. [Google Maps] Afficher une ligne sur la carte google Map
    Par bza88 dans le forum APIs Google
    Réponses: 1
    Dernier message: 24/12/2013, 17h55
  3. Afficher l'itinéraire sur google MAP
    Par loviso dans le forum API standards et tierces
    Réponses: 0
    Dernier message: 05/08/2012, 19h37
  4. Afficher une vidéo sur mon site à partir d'une url ou permalien comme facebook ?
    Par shivato dans le forum EDI, CMS, Outils, Scripts et API
    Réponses: 1
    Dernier message: 24/06/2010, 11h08

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo