Bonjour,
Je suis actuellement un stagiaire dans une entreprise et on me demande de migrer le page de Google Map API V2 vers V3 pour une application GPS. J'ai changé tous les code que je pense il faut grâce aux aides des plusieurs forum y compris stackoverflow. Mais il marche toujours pas où les problèmes sont le map n'affiche pas les markers comme il faut. En général c'est comme ça, quand on ouvre une application windows, elle va ouvrir le page de Google Map, ce qui dois se passer sont comme suivant :

1) le map est centrer sur un coordinate Lat et Long donnée,

2) Tous les véhicules qui sont en route va nous envoyer leur informations comme Lat,Long,Vitesse, immat(nom de chaque véhicule), etc. Les informations vont être stocké dans SQL Serveur.

3) le map afficher tous les markers des véhicules qui sont en route. Quand on clique sur chaque marker, il affiche un infowindow qui contient leur propre information.

4) Il y a une liste des véhicules qui sont en route et quand on clique sur une véhicule, le map va se centrer sur le coordinate de cette voiture et aussi afficher un infowindow qui affiche des informations comme dans le code, et il répète quand on clique sur des autres véhicules.

J'ai besoin des aides pour la vérification de codage de Google Maps API V3. Merci en avance.

Google Maps API V2
Code css : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
<!-- ============== create a style for the tooltip ============ -->
<style type="text/css">
  .tooltip {
    background-color:#ffffff;
    font-weight:bold;
    border:2px #006699 solid;
  }
</style>
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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
<script type="text/javascript">
// v\:* { behavior:url(#default#VML); } 
// -------------------------------------------- 
//
// Zone dédiée à la programmation en JavaScript
//
// --------------------------------------------
// Variables globales
// ------------------
var map = null;
var Table_Pins = {};     // Liste des Pins affichées
var Pos_Info = null;     // Dit sur quel marker se situe l'infobulle
var Liste_Points = []; // Pour la mémorisation du tracé
var route = null;
var tooltip = null;
//
// Ouverture du WebBrowser
// -----------------------
function load() {
    try {
        map = new GMap2(document.getElementById("map"));
        map.addControl(new GLargeMapControl()); //Zoom
        map.addControl(new GMapTypeControl()); //Type de carte
        map.setMapType(G_NORMAL_MAP);
        map.addControl(new GScaleControl()); //Echelle
        map.enableScrollWheelZoom();
        map.enableContinuousZoom();
        tooltip = document.createElement("div");
        document.getElementById("map").appendChild(tooltip);
        tooltip.style.visibility = "hidden";
 
    }
    catch (ex) {
        alert("vous devez etre connecte a l'internet...");
    }
 
    if (map != null) {
        //Centrer la carte sur "Roquefort : zoom = 15
        map.setCenter(new GLatLng(43.665, 7.052), 15);
    }
}
// ------------------------------------------------------------------------------------
//
//                          Affichage d'un véhicule
//
// ------------------------------------------------------------------------------------
function Affiche_Pin(Lat, Long, immat, type, site, vitesse, date) {
    var myPin = Table_Pins[immat];
    if (typeof (myPin) != "undefined") 
    {
        // La Pin est déja placée, on la déplace
        // -------------------------------------
        myPin.setLatLng(new GLatLng(Lat, Long))
        myPin.html = '<b>Véhicule <font color="green">' + immat + ' ' + '</font></b><br>' +
            'Site : ' + site + '<br>' +
            'Type : ' + type + '<br>' +
            'Vitesse : ' + vitesse + ' km/h' + '<br>' +
            'Date : ' + date + '<br>';
        if (Pos_Info == myPin) 
        {
            var infowin = map.getInfoWindow();
                if (infowin.isHidden() == false) 
                {
                    myPin.openInfoWindowHtml(myPin.html);
                }
            }  
    }
    else {
        // -------------------------------
        // Création de la Pin et placement
        // -------------------------------
var func_icon = new GIcon();
        func_icon.image = "http://maps.google.com/mapfiles/kml/pal4/icon15.png";
        func_icon.iconSize = new GSize(32, 32);
        func_icon.shadowSize = new GSize(56, 32);
        func_icon.iconAnchor = new GPoint(16, 32);
        func_icon.infoWindowAnchor = new GPoint(16, 0);
        var func_markerOpts = {};
        func_markerOpts.icon = func_icon;
        var func_marker = new GMarker(new GLatLng(Lat, Long), func_markerOpts);
        func_marker.html = '<b>Véhicule <font color="green">' + immat + ' ' + '</font></b><br>' +
            'Site : ' + site + '<br>' +
            'Type : ' + type + '<br>' +
            'Vitesse : ' + vitesse + ' km/h' + '<br>' +
            'Date : ' + date + '<br>';
        // ---------------------------
        // Evenement "Click" du marker
        // ---------------------------
        GEvent.addListener(func_marker, "click", function() {
            func_marker.openInfoWindowHtml(func_marker.html);
        });
        // ------------------------------------
        // Evenement "infowindowopen" du marker
        // ------------------------------------
        GEvent.addListener(func_marker, "infowindowopen", function() {
            Pos_Info = func_marker;
        });
        Table_Pins[immat] = func_marker;
        map.addOverlay(func_marker);
    }
 
}
// ------------------------------------------------------------------------------------
//
//                          On centre le véhicule
//
// ------------------------------------------------------------------------------------
function Centrer_Pin(immat) {
    var myPin = Table_Pins[immat];
    if (typeof (myPin) != "undefined") {
        map.setCenter(myPin.getLatLng());
        myPin.openInfoWindowHtml(myPin.html);
    }
}
// ------------------------------------------------------------------------------------
//
//                          On Efface un parcours
//
// ------------------------------------------------------------------------------------
function Clear_Trace() {
    // Clear current map and reset arrays
    map.clearOverlays();
    Liste_Points = [];
//     markers.length = 0;
}
 
// ------------------------------------------------------------------------------------
//
//                          On trace un parcours
//
// ------------------------------------------------------------------------------------
function Trace_Pin(Lat, Long, immat, type, site, vitesse, date) {
    var func_icon = new GIcon();
    func_icon.image = "http://maps.google.com/mapfiles/kml/pal3/icon61.png";
    func_icon.iconSize = new GSize(32, 32);
    func_icon.shadowSize = new GSize(56, 32);
    func_icon.iconAnchor = new GPoint(16, 16);
    func_icon.infoWindowAnchor = new GPoint(16, 0);
    var func_markerOpts = {};
    func_markerOpts.icon = func_icon;
    var marker = new GMarker(new GLatLng(Lat, Long), func_markerOpts);
    marker.tooltip = '<div class="tooltip">' + 'Date : ' + date + '<br>' + 'Vitesse : ' + vitesse + ' km/h' + '<br>' + '<\/div>';
    map.addOverlay(marker);
    Liste_Points.push(marker.getPoint());
    // Evenement MouseOver :
    // -------------------
    GEvent.addListener(marker, "mouseover", function() {
    showTooltip(marker);
    });
    // Evenement MouseOut :
    // ------------------
    GEvent.addListener(marker, "mouseout", function() {
    tooltip.style.visibility = "hidden"
    });
}
// ------------------------------------------------------------------------------------
//
//                          On joint les points du parcours
//
// ------------------------------------------------------------------------------------
function Trace_Route() {
   if (route) { map.removeOverlay(route); }
   if (Liste_Points.length > 1) {
        route = new GPolyline(Liste_Points);
        map.addOverlay(route);
    }
}
// ------------------------------------------------------------------------------------
//
//                          Gestion des tooltips
//
// ------------------------------------------------------------------------------------
function showTooltip(marker) { // Display tooltips
    tooltip.innerHTML = marker.tooltip;
    var point = map.getCurrentMapType().getProjection().fromLatLngToPixel(map.getBounds().getSouthWest(), map.getZoom());
    var offset = map.getCurrentMapType().getProjection().fromLatLngToPixel(marker.getPoint(), map.getZoom());
    var anchor = marker.getIcon().iconAnchor;
    var width = marker.getIcon().iconSize.width;
    var pos = new GControlPosition(G_ANCHOR_BOTTOM_LEFT, new GSize(offset.x - point.x - anchor.x + width, -offset.y + point.y + anchor.y));
    pos.apply(tooltip);
    tooltip.style.visibility = "visible";
}
</script>
Google Maps API V3
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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
<script type="text/javascript">
		//Creation de Map
		// Variables globales
        // ------------------
	 	var map = null;
		var Table_Pins = {};     // Liste des Pins affichées
        var Pos_Info = null;     // Dit sur quel marker se situe l'infobulle
        var Liste_Points = []; // Pour la mémorisation du tracé
        var route = null;
 
		//-----------------------------------------------------------------
			function initialize() {
				var mapOptions = {
					zoom: 15,
                    center: new google.maps.LatLng(43.665, 7.052),
                    mapTypeId: google.maps.MapTypeId.ROADMAP, //Type de carte
                    mapTypeControl: true,
                    panControl: true,
                    zoomControl: true, //Zoom
                    scaleControl: true, //Echelle
	                scaleControlOptions: {
                    position: google.maps.ControlPosition.LEFT_BOTTOM},
                    streetViewControl: true
                    } ;
				var map = new google.maps.Map(document.getElementById("map_canvas"), mapOptions);
			}
				//------------------------
                // Ouverture du WebBrowser
                // -----------------------
			try { google.maps.event.addDomListener(window, 'load', initialize);}
	        catch (ex){ alert("vous devez etre connecte a l'internet...");}
 
 
		// ------------------------------------------------------------------------------------
        //                          Affichage des véhicules
        // ------------------------------------------------------------------------------------
 
		function Affiche_Pin(Lat, Long, immat, type, site, vitesse, date)
		{ 
		for ( immat in Table_Pins)
		{ 
		  var myPin = Table_Pins[immat];
		  myPin.html ='<b>Véhicule <font color="green">' + immat + ' ' + '</font></b><br>' +
                'Site : ' + site + '<br>' +
                'Type : ' + type + '<br>' +
                'Vitesse : ' + vitesse + ' km/h' + '<br>' +
                'Date : ' + date + '<br>';
 
		if (typeof myPin != "undefined") 
	     {
		 myPin.setLatLng(new google.maps.LatLng(Lat, Long))
	      // La Pin est déja placée, on la déplace
          // -------------------------------------
	       map = new google.maps.Map(document.getElementById('map')); 
	       map.setCenter(new google.maps.LatLng(Lat, Long));
	       map.setZoom(15);
		   map.setMapTypeId(google.maps.MapTypeId.ROADMAP);
 
	       if (Pos_Info == myPin) {
	       var infowindow = new google.maps.InfoWindow({
           content: myPin.html,	
	       position: new google.maps.LatLng(Lat, Long) });
		   infowindow.open(map);
		   } //end if (pos_info)
	     }//end if (mypin)
 
		 else{
 
 
	     var image = {
         url: 'http://maps.google.com/mapfiles/kml/pal4/icon15.png',
         size: new google.maps.Size(32, 32),
         anchor: new google.maps.Point(16, 32)};
 
	     var vehlatlng = new google.maps.LatLng(Lat, Long) ;
	     var marker = new google.maps.Marker({
	     map: map,
	     position: vehlatlng,
	     icon: image	});
 
         var infowindow = new google.maps.InfoWindow({
         content: myPin.html,	
	     position: vehlatlng });
	      }//end else
 
		 // Evenement "Click" et "infowindowopen" du marker
         // ---------------------------
	      google.maps.event.addListener(marker, 'tilesloaded', function() {
              if(lastOpenInfoWin) lastOpenInfoWin.close();
			  lastOpenInfoWin = infowindow;
			  infowindow.open(marker.get('map'), marker); 
	          Pos_Info = marker;});
 
	      Table_Pins[immat] = marker;
	      marker.setMap(map);
 
		 } //end for
 
	  }//end function affiche_pin
 
	// ------------------------------------------------------------------------------------
    //                          On centre le véhicule
    // ------------------------------------------------------------------------------------
    function Centrer_Pin(immat) {
	var myPin = Table_Pins[immat];
        if (typeof myPin != "undefined") 
		{ getPosition();
	       map.setCenter(myPin.getPosition());
	       infowindow.open(map);
        }*/ 
 
 
    }
	// ------------------------------------------------------------------------------------
    //                          On Efface un parcours
    // ------------------------------------------------------------------------------------
	// Deletes all markers in the array by removing references to them
       function Clear_Trace() 
	   {
           if (Liste_Points) {
           for (var i in Liste_Points) {
           Liste_Points[i].setMap(null); }
           Liste_Points.length = 0;}
       }
	 // ------------------------------------------------------------------------------------
    //                          On trace un parcours
    // ------------------------------------------------------------------------------------
	function Trace_Pin(Lat, Long, immat, type, site, vitesse, date)
	{ var image = {
         url: 'http://maps.google.com/mapfiles/kml/pal4/icon15.png',
         size: new google.maps.Size(32, 32),
         anchor: new google.maps.Point(16, 32)};
 
	  var vehlatlng = new google.maps.LatLng(Lat, Long) ;
	  var marker = new google.maps.Marker({
	     map: map,
	     position: vehlatlng,
	     icon: image	});
	  marker.tooltip = '<div class="tooltip">' + 'Date : ' + date + '<br>' + 'Vitesse : ' + vitesse + ' km/h' + '<br>' + '<\/div>';	 
	  marker.setMap(map);
	  Liste_Points.push(marker.getPoint());
       }
	 // ------------------------------------------------------------------------------------
     //                          On joint les points du parcours
    // ------------------------------------------------------------------------------------
    function Trace_Route() {
       if (route) { map.removeOverlay(route); }
       if (Liste_Points.length > 1) {
            route = new google.maps.Polyline({
                    path: Liste_Points,
                    strokeColor: "#FF0000",
                    strokeOpacity: 1.0,
                    strokeWeight: 2});
            route.setMap(map);
        }
    }
    // ------------------------------------------------------------------------------------
    //                          Gestion des tooltips
    // ------------------------------------------------------------------------------------
    /* function showTooltip(marker) { // Display tooltips
        tooltip.innerHTML = marker.tooltip;
        var point = map.getCurrentMapType().getProjection().fromLatLngToPixel(map.getBounds().getSouthWest(), map.getZoom());
        var offset = map.getCurrentMapType().getProjection().fromLatLngToPixel(marker.getPoint(), map.getZoom());
        var anchor = marker.getIcon().iconAnchor;
        var width = marker.getIcon().iconSize.width;
        var pos = new GControlPosition(G_ANCHOR_BOTTOM_LEFT, new GSize(offset.x - point.x - anchor.x + width, -offset.y + point.y + anchor.y));
        pos.apply(tooltip);
        tooltip.style.visibility = "visible";
    } */	  
	  	function createTooltip(marker, immat) {
				//create a tooltip 
				var tooltipOptions={
					marker:marker,
					content:marker.tooltip,
					cssClass:'tooltip' // name of a css class to apply to tooltip
				};
				var tooltip = new Tooltip(tooltipOptions);
 
	}
	var lastOpenInfoWin = null;
 
	</script>
	<script type="text/javascript">
		// tooltips javascript
		function Tooltip(options) 
           {// Now initialize all properties.
           this.marker_ = options.marker;
           this.content_ = options.content;
           this.map_ = options.marker.get('map');
	       this.cssClass_ = options.cssClass||null;
           this.div_ = null;
           //Explicitly call setMap on this overlay
           this.setMap(this.map_);
	       var me = this;
	       // Show tooltip on mouseover event.
	       google.maps.event.addListener(me.marker_, 'mouseover', function() {
		   me.show();});
	       // Hide tooltip on mouseout event.
	       google.maps.event.addListener(me.marker_, 'mouseout', function() {
	    	me.hide();});
           }
           // Now we extend google.maps.OverlayView()
        Tooltip.prototype = new google.maps.OverlayView();
 
        // onAdd is one of the functions that we must implement, 
        // it will be called when the map is ready for the overlay to be attached.
        Tooltip.prototype.onAdd = function() 
		{
             // Create the DIV and set some basic attributes.
             var div = document.createElement('DIV');
             div.style.position = "absolute";
	         // Hide tooltip
	         div.style.visibility = "hidden";
	         if(this.cssClass_)
		     div.className += " "+this.cssClass_;
 
            //Attach content to the DIV.
            div.innerHTML = this.content_;
 
            // Set the overlay's div_ property to this DIV
            this.div_ = div;
 
           // We add an overlay to a map via one of the map's panes.
           // We'll add this overlay to the floatPane pane.
           var panes = this.getPanes();
  	       panes.floatPane.appendChild(this.div_);
	      }
           // We here implement draw
           Tooltip.prototype.draw = function() 
		   {
               // Position the overlay. We use the position of the marker
               // to peg it to the correct position, just northeast of the marker.
               // We need to retrieve the projection from this overlay to do this.
              var overlayProjection = this.getProjection();
 
              // Retrieve the coordinates of the marker
              // in latlngs and convert them to pixels coordinates.
              // We'll use these coordinates to place the DIV.
              var ne = overlayProjection.fromLatLngToDivPixel(this.marker_.getPosition());
 
              // Position the DIV.
              var div = this.div_;
              div.style.left = ne.x + 'px';
              div.style.top = ne.y + 'px';
            }
            // We here implement onRemove
            Tooltip.prototype.onRemove = function() 
			{
                this.div_.parentNode.removeChild(this.div_);
            }
 
             // Note that the visibility property must be a string enclosed in quotes
             Tooltip.prototype.hide = function() 
			 {
                  if (this.div_) 
				  {
                  this.div_.style.visibility = "hidden";
                  }
              }
 
              Tooltip.prototype.show = function() 
			  {
                   if (this.div_) 
				   {
                   this.div_.style.visibility = "visible";
                   }
              }
 
		</script>