Ver Mensaje Individual
  #10 (permalink)  
Antiguo 27/10/2011, 08:55
Avatar de CyberKabexa
CyberKabexa
 
Fecha de Ingreso: octubre-2011
Ubicación: Merida
Mensajes: 6
Antigüedad: 12 años, 6 meses
Puntos: 4
Respuesta: Superposiciones en google maps con movimiento

Con este código pinto el mapa:

Código Javascript:
Ver original
  1. var map;
  2.     function initialize() {
  3.         var latlng = new google.maps.LatLng(15.623037,-90.351562);
  4.         var settings = {
  5.             zoom: 4,
  6.             center: latlng,
  7.             mapTypeControl: true,
  8.             mapTypeControlOptions: {style: google.maps.MapTypeControlStyle.DROPDOWN_MENU},
  9.             navigationControl: true,
  10.             navigationControlOptions: {style: google.maps.NavigationControlStyle.ZOOM_PAN},
  11.             mapTypeId: google.maps.MapTypeId.ROADMAP
  12.     };
  13.  
  14. map = new google.maps.Map(document.getElementById("map_canvas"), settings);
  15.  
  16. setInterval("unidades()",2000);
  17. //unidades()
  18.  
  19. }
  20.  
  21.  
  22.       google.maps.event.addDomListener(window, 'load', initialize);

con setInterval llamó cada 2 segundos a la funcion unidades que es la que me muestra la ubicación del vehículo así como su trayectoria recorrida. Te la comparto, es esta:

Código Javascript:
Ver original
  1. function unidades(){
  2.  
  3. <?Php
  4.     $imei_sql="EXEC sp_GetIMEI";
  5.     $res_imei=mssql_query($imei_sql);
  6.    
  7.     while($array_imei=mssql_fetch_array($res_imei)){
  8.     $imei=$array_imei['IMEI'];
  9.     $sqlquery="EXEC sp_GetLastRecord '$imei'";
  10.     $res_sqlquery=mssql_query($sqlquery);
  11.     $ar_sqlquery=mssql_fetch_array($res_sqlquery);
  12.     //$latitud=$ar_query['LATITUDE'];
  13.     //$longitud=$ar_query['LONGITUDE'];
  14.     //$imei=$ar_query['IMEI'];
  15.     //$speed=$ar_query['SPEED'];
  16. ?>
  17.  
  18. var contentString = '<div class="content">'+
  19.                     '<div class="siteNotice">'+
  20.                     '</div>'+
  21.                     '<h3 class="firstHeading"><?Php echo $array_imei['NAME']; ?></h3>'+
  22.                     '<div class="bodyContent">'+
  23.                     '<p><?Php echo $ar_sqlquery['IMEI']; ?></p>'+
  24.                     '<p>Latitude: <?Php echo $ar_sqlquery['LATITUDE']; ?></p>'+
  25.                     '<p>Longitud: <?Php echo $ar_sqlquery['LONGITUDE']; ?></p>'+
  26.                     '<p>Velocidad: <?Php echo $ar_sqlquery['SPEED']; ?> Km/h</p>'+
  27.                     '<p><?Php echo $ar_sqlquery['TIMESTAMP']; ?></p>'+
  28.                     '<p><a target="_blank" href="http://maps.google.com/maps?f=q&q=<?Php echo $ar_sqlquery['LATITUDE']; ?>,<?Php echo $ar_sqlquery['LONGITUDE']; ?>&z=16">Ver en Google maps</a></p>'+
  29.                     '</div>'+
  30.                     '</div>';
  31.                 var infowindow<?Php echo $cont; ?> = new google.maps.InfoWindow({
  32.                     content: contentString
  33.                 });
  34.  
  35. /*Car*/
  36. var carLogo = new google.maps.MarkerImage('images/car.png',
  37.     new google.maps.Size(40,40),
  38.     new google.maps.Point(0,0),
  39.     new google.maps.Point(20,20)
  40. );
  41.  
  42. var carPos = new google.maps.LatLng(<?Php echo $ar_sqlquery['LATITUDE']; ?>,<?Php echo $ar_sqlquery['LONGITUDE']; ?>);
  43. var carMarker<?Php echo $cont; ?> = new google.maps.Marker({
  44.     position: carPos,
  45.     map: map,
  46.     icon: carLogo,
  47.     title:"<?Php echo $array_imei['NAME']; ?>"
  48. });
  49.  
  50. /*Muestra globo con la info*/
  51. google.maps.event.addListener(carMarker<?Php echo $cont; ?>, 'click', function() {
  52. infowindow<?Php echo $cont; ?>.open(map,carMarker<?Php echo $cont; ?>);
  53. });
  54.  
  55. /*Polilínea*/
  56. var Ruta = [
  57.                   <?Php
  58.                   $sql="EXEC sp_GetLastHundred '$imei'";
  59.                   $res_sql=mssql_query($sql);
  60.                   //$ar_sql=mssql_fetch_array($res_sql)
  61.                   while ($ar_sql=mssql_fetch_array($res_sql)){
  62.                   echo 'new google.maps.LatLng('.$ar_sql['LATITUDE'].','.$ar_sql['LONGITUDE'].'), ';
  63.                   } ?>
  64.                  
  65.                  
  66.     ];
  67.  
  68.   var carPath = new google.maps.Polyline({
  69.     path: Ruta,
  70.     strokeColor: "#FF0000",
  71.     strokeOpacity: 1.0,
  72.     strokeWeight: 4
  73.   });
  74.  
  75.   carPath.setMap(map);
  76.  
  77. <?Php $cont++; } ?>
  78. }

En la función unidades es donde hago la consulta a la BD.