Ver Mensaje Individual
  #1 (permalink)  
Antiguo 14/06/2016, 20:06
byrong
 
Fecha de Ingreso: enero-2016
Ubicación: Venezuela
Mensajes: 139
Antigüedad: 8 años, 3 meses
Puntos: 3
Agregar varios scripts (Mapas)

Tengo el siguiente problema, en el google maps utilizó el siguiente código:

Código Javascript:
Ver original
  1. function localizame() {
  2.             if (navigator.geolocation) { /* Si el navegador tiene geolocalizacion */
  3.                 navigator.geolocation.getCurrentPosition(coordenadas, errores);
  4.             }else{
  5.                 alert('Oops! Tu navegador no soporta geolocalización. Bájate Chrome, que es gratis!');
  6.             }
  7.         }
  8.        
  9.         function coordenadas(position) {
  10.             latitud = position.coords.latitude; /*Guardamos nuestra latitud*/
  11.             longitud = position.coords.longitude; /*Guardamos nuestra longitud*/
  12.         }
  13. function getCoords(marker){
  14.     document.getElementById("latitud").value=''+marker.getPosition().lat();
  15.       document.getElementById("longitud").value=''+marker.getPosition().lng();
  16. }
  17. function initialize() {
  18.     var myLatlng = new google.maps.LatLng(9.314299432752295,-70.60566794257812);
  19.     var myOptions = {
  20.         zoom: 17,
  21.         center: myLatlng,
  22.         mapTypeId: google.maps.MapTypeId.ROADMAP,
  23.     }
  24.     var map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);
  25.      
  26.    marker = new google.maps.Marker({
  27.           position: myLatlng,
  28.           draggable: true,
  29.           title:"Descubrelo"
  30.     });
  31.     google.maps.event.addListener(marker, "dragend", function() {
  32.                     getCoords(marker);
  33.     });
  34.      
  35.       marker.setMap(map);
  36.     getCoords(marker);
  37.      
  38.    
  39.   }
Pero tengo un select que me muestra un mapa según cada opción, pero es el mismo mapa, el código es este:
Código Javascript:
Ver original
  1. $(document).ready(function(){
  2.                 $(".contenido").hide();
  3.                 $("#planes").change(function(){
  4.                 $(".contenido").hide();
  5.                      $("#div_" + $(this).val()).toggle("slow", function(){
  6.                       google.maps.event.trigger(initialize(), 'resize');
  7.                   });
  8.                 });
  9.             });
El primer mapa lo tengo de la siguiente manera en el primer div:
Código HTML:
Ver original
  1. <div id="map_canvas" style="width:400px; height:400px"></div><br>
y me lo muestra perfecto acá, pero en el segundo y tercer div lo tengo de la misma manera y me sale en blanco, es decir no carga, intenté cambiando en el html esto <div id="map_canvas2"> y en el js lo puse así para probar, pero sigue igual:

Código Javascript:
Ver original
  1. function localizame2() {
  2.             if (navigator.geolocation) { /* Si el navegador tiene geolocalizacion */
  3.                 navigator.geolocation.getCurrentPosition(coordenadas2, errores);
  4.             }else{
  5.                 alert('Oops! Tu navegador no soporta geolocalización. Bájate Chrome, que es gratis!');
  6.             }
  7.         }
  8.        
  9.         function coordenadas2(position) {
  10.             latitud = position.coords.latitude; /*Guardamos nuestra latitud*/
  11.             longitud = position.coords.longitude; /*Guardamos nuestra longitud*/
  12.         }
  13. function getCoords2(marker){
  14.     document.getElementById("latitud").value=''+marker.getPosition().lat();
  15.       document.getElementById("longitud").value=''+marker.getPosition().lng();
  16. }
  17. function initialize2() {
  18.     var myLatlng = new google.maps.LatLng(9.314299432752295,-70.60566794257812);
  19.     var myOptions = {
  20.         zoom: 17,
  21.         center: myLatlng,
  22.         mapTypeId: google.maps.MapTypeId.ROADMAP,
  23.     }
  24.     var map = new google.maps.Map(document.getElementById("map_canvas2"), myOptions);
  25.      
  26.    marker = new google.maps.Marker({
  27.           position: myLatlng,
  28.           draggable: true,
  29.           title:"Descubrelo"
  30.     });
  31.     google.maps.event.addListener(marker, "dragend", function() {
  32.                     getCoords2(marker);
  33.     });
  34.      
  35.       marker.setMap(map);
  36.     getCoords2(marker);
  37.      
  38.    
  39.   }

Que puedo hacer para solucionarlo? los div 2 y 3 me lo muestran blanco usándolo de esa y la otra manera, Gracias.