Ver Mensaje Individual
  #1 (permalink)  
Antiguo 26/11/2012, 12:09
Avatar de maximendez88
maximendez88
 
Fecha de Ingreso: septiembre-2012
Ubicación: Montevideo
Mensajes: 131
Antigüedad: 11 años, 7 meses
Puntos: 3
Sonrisa como guardar marcadores de google maps en un cookie?

buenas, bueno la pregunta me parece bastante clara, estoy intentando guardar maracadores de google maps en cookies para mantener la ruta o redibujarla aunque se actualice el navegador... he intentado hacer algo como esto... pero aun no logro comprender como poder hacerlo... espero que alguien se apiade de mi alma y me ayude... saludos, dejo mi codigo por las dudas



Código HTML:
Ver original
  1.     <head>
  2.     <meta charset="utf-8" />
  3.      <script src="https://maps.googleapis.com/maps/api/js?sensor=false"></script>
  4.     <title>Test Google Maps</title>
  5.  
  6.  
  7. <script type="text/javascript">
  8.     function mantenermapa()
  9.     {
  10.         if(document.cookie!="")
  11.         {
  12.              initialize();
  13.         }
  14.     }
  15.  
  16.  
  17.  
  18.  
  19.  
  20.  
  21.  
  22.     </head>
  23. <body onload="mantenermapa()">
  24.         <!-- MAPA -->
  25.         <div id="map_canvas" style="width: 600px; height: 600px;"></div>
  26.         <input type="text" name="ciudad" id="ciudad" /> <button onclick="agregarCiudad();">Agregar</button>
  27.        
  28.         <!-- funcion para agregar ciudad. La separo porque es sólo ejemplo -->
  29.         <script type="text/javascript">
  30.             function agregarCiudad(){
  31.                 showAddress(document.getElementById('ciudad').value);
  32.                 document.cookie="ciudad = document.getElementById('ciudad'); expires = 2 Dec 2015 23:59:59 GMT"
  33.  
  34.  
  35.                 document.getElementById('ciudad').value = '';
  36.             }
  37.         </script>
  38.        
  39.         <script type="text/javascript">
  40.         //variables y objetos globales
  41.         var map             //mapa
  42.         var geocoder;       //geocoder
  43.         var _path = [];     // ruta
  44.         var _poliLinea = new google.maps.Polyline({ //polilinea
  45.             path: _path,
  46.             strokeColor: '#FF0000',
  47.             strokeOpacity: 1.0,
  48.             strokeWeight: 2
  49.         });
  50.      
  51.         //inicializo
  52.         initialize();
  53.      
  54.         function initialize() {
  55.             //centrado
  56.             var myLatLng = new google.maps.LatLng(37.4419, -122.1419);
  57.             //opciones
  58.             var mapOptions = {
  59.                 zoom: 1,
  60.                 center: myLatLng,
  61.                 mapTypeId: google.maps.MapTypeId.TERRAIN
  62.             };
  63.             //geocoder
  64.             geocoder = new google.maps.Geocoder();
  65.             //creo mapa
  66.             map = new google.maps.Map(document.getElementById('map_canvas'), mapOptions);
  67.            
  68.             //asigno polilinea al mapa
  69.             _poliLinea.setMap(map);
  70.         }
  71.      
  72.         function showAddress(s_address) {
  73.             var address = s_address;
  74.             //busco la direccion dada
  75.             geocoder.geocode( { 'address': address}, function(results, status) {
  76.               if (status == google.maps.GeocoderStatus.OK) {
  77.                 //centro el mapa en el resultado
  78.                 map.setCenter(results[0].geometry.location);
  79.                 //creo marcador
  80.                 var marker = new google.maps.Marker({
  81.                     map: map,
  82.                     position: results[0].geometry.location
  83.                 });
  84.                 //agrego punto a la linea
  85.                 agregarRuta(results[0].geometry.location)
  86.               } else {
  87.                 alert('Error: ' + status);
  88.               }
  89.             });
  90.          }
  91.          
  92.         function agregarRuta(o_punto){
  93.             //creo punto a partir de la dirección dada
  94.             var o_LL = new google.maps.LatLng(o_punto.Xa, o_punto.Ya)
  95.             //agrego el punto al array de la ruta
  96.             _path.push(o_LL);
  97.             //cargo la nueva ruta en la polilinea
  98.             _poliLinea.setPath(_path);
  99.             //centro el mapa en el último punto
  100.             map.setCenter(o_LL);
  101.             //Hago un poco de zoom
  102.             map.setZoom(6);
  103.         }
  104.         </script>
  105.     </body>
  106.     </html>