bonjour,
est ce qu'une personne peu m'aider a résoudre juste un petit truc pour mon
sript qui utilise l'API de google maps.

je veux utiliser distance matrix service et géolocation

mon script :

Code : 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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
function initMap() {
  var bounds = new google.maps.LatLngBounds;
  var markersArray = [];
 
  var map = new google.maps.Map(document.getElementById('map'), {
    center: {lat: 44.53418092456276, lng: 4.409133195877075},
    zoom: 10
  });
 
 
 
 
  var infoWindow = new google.maps.InfoWindow({map: map});
 
 // if (navigator.geolocation) {
   navigator.geolocation.getCurrentPosition(function(position) {
      var pos = {
        lat: position.coords.latitude,
        lng: position.coords.longitude
      };
 
      infoWindow.setPosition(pos);
      infoWindow.setContent('Vous etes Ici.');
    });
 // }
 
 
// probleme ici avec ma VAR 'pos1', je n'arive pas a reprendre lat et lng de la géolocalisation de plus haut.
// elle doit etre du type lat: 44.53418092456276, lng: 4.409133195877075
 
   var pos1 = {};
 
 
  var destination = {lat: 44.53418092456276, lng: 4.409133195877075};
 
  var destinationIcon = 'https://chart.googleapis.com/chart?' +
      'chst=d_map_pin_letter&chld=D|FF0000|000000';
  var originIcon = 'https://chart.googleapis.com/chart?' +
      'chst=d_map_pin_letter&chld=O|FFFF00|000000';
 
 
 
 
  var geocoder = new google.maps.Geocoder;
 
  var service = new google.maps.DistanceMatrixService;
  service.getDistanceMatrix({
    origins: [pos1],
    destinations: [destination],
    travelMode: google.maps.TravelMode.DRIVING,
    unitSystem: google.maps.UnitSystem.METRIC,
    avoidHighways: false,
    avoidTolls: false
  }, function(response, status) {
    if (status !== google.maps.DistanceMatrixStatus.OK) {
      alert('Error was: ' + status);
    } else {
      var originList = response.originAddresses;
      var destinationList = response.destinationAddresses;
      var outputDiv = document.getElementById('output');
      outputDiv.innerHTML = '';
      deleteMarkers(markersArray);
 
      var showGeocodedAddressOnMap = function(asDestination) {
        var icon = asDestination ? destinationIcon : originIcon;
        return function(results, status) {
          if (status === google.maps.GeocoderStatus.OK) {
            map.fitBounds(bounds.extend(results[0].geometry.location));
            markersArray.push(new google.maps.Marker({
              map: map,
              position: results[0].geometry.location,
              icon: icon
            }));
          } else {
            alert('Geocode was not successful due to: ' + status);
          }
        };
      };
 
      for (var i = 0; i < originList.length; i++) {
        var results = response.rows[i].elements;
        geocoder.geocode({'address': originList[i]},
            showGeocodedAddressOnMap(false));
        for (var j = 0; j < results.length; j++) {
          geocoder.geocode({'address': destinationList[j]},
              showGeocodedAddressOnMap(true));
          outputDiv.innerHTML += originList[i] + ' to ' + destinationList[j] +
              ': ' + results[j].distance.text + ' in ' +
              results[j].duration.text + '<br>';
        }
      }
    }
  });
}
 
function deleteMarkers(markersArray) {
  for (var i = 0; i < markersArray.length; i++) {
    markersArray[i].setMap(null);
  }
  markersArray = [];
}
je n’arrive pas a reprendre la VAR de la géolocalisation pour le reste
voir dans le script.

quelqu'un a une idé(s) ???

Merci par avance.