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>