Foros del Web » Programando para Internet » Javascript »

Problema con google maps

Estas en el tema de Problema con google maps en el foro de Javascript en Foros del Web. Buenas tardes, estoy realizando una web la cual cuanta con un light box dentro de este inserto el mapa, la primera vez al abrir el ...
  #1 (permalink)  
Antiguo 23/02/2011, 17:38
 
Fecha de Ingreso: mayo-2009
Mensajes: 242
Antigüedad: 14 años, 11 meses
Puntos: 2
Pregunta Problema con google maps

Buenas tardes, estoy realizando una web la cual cuanta con un light box dentro de este inserto el mapa, la primera vez al abrir el light box se visualiza bien el marker ke puse y el mapa se cargar bien, pero al cerrar la ventana y abrirla otra vez el mapa no se carga bien y el marker se mueve al hacer zoom, este codigo lo mando llamar cada vez que abro el lightbox.
Código:
 function CargarMapa(latitud,longitud,imgMap){ 
      var directionDisplay = new google.maps.DirectionsRenderer();
	  var directionsService = new google.maps.DirectionsService();
	  var lat = ""; 
	  var long = "";
	  var myOptions = {
			zoom: 16,
			mapTypeId: google.maps.MapTypeId.ROADMAP
	  };
	  var Empresalatlng = new google.maps.LatLng(latitud,longitud);
	  var map = new google.maps.Map(document.getElementById("mapa"), myOptions);
	  map.setCenter(Empresalatlng);
	  directionDisplay.setMap(map);
	  var MiposicionControlDiv = document.createElement('DIV');
      var MiposicionControl = new MiPosicionControl(MiposicionControlDiv);
      MiposicionControlDiv.index = 1;
      map.controls[google.maps.ControlPosition.TOP_RIGHT].push(MiposicionControlDiv);
	  
	  //Etiqueta del anuncio
	  setMarkers(map,"",latitud,longitud);
	  
	  function MiPosicionControl(controlDiv) {
		controlDiv.style.paddingTop = '7.5px';
		var controlUI = document.createElement('SELECT');
		controlUI.setAttribute('class','tiporuta');
		var elegir = document.createElement('OPTION');
		var opcCaminando = document.createElement('OPTION');
		opcCaminando.setAttribute('value','WALKING');
		var opcAuto = document.createElement('OPTION');
		opcAuto.setAttribute('value','DRIVING');
		var opcAutobus = document.createElement('OPTION');
		opcAutobus.setAttribute('value','BICYCLING');
		elegir.innerHTML = 'Como Llego Aquí';
		opcCaminando.innerHTML = '1.- Ire caminando';
		opcAuto.innerHTML = '2.- Ire en automóvil';
		opcAutobus.innerHTML = '3.- Ire en autobus';
		controlUI.appendChild(elegir);
		controlUI.appendChild(opcCaminando);
		controlUI.appendChild(opcAuto);
		controlUI.appendChild(opcAutobus);
		controlUI.style.fontSize = '11px';
		controlUI.title = 'Obten la ruta para llegar desde tu ubicación.';
		controlDiv.appendChild(controlUI);
		google.maps.event.addDomListener(controlUI,'click',function(){
			 $('.tiporuta').change(function() {
				ObtenerPosicionDeUsuario(controlUI.value);
             });
        });
	  }
	  
	  function setMarkers(map,posicionuser,lat,long) {
		var ImagenSeleccionada = "";
		if(posicionuser == ""){  
		  ImagenSeleccionada = base_url+'imagenes/iconosmapa/'+imgMap+'.png';
		}else if(posicionuser == "user"){
		  ImagenSeleccionada = base_url+'imagenes/iconosmapa/posicion.png';
		}
		var image = new google.maps.MarkerImage(ImagenSeleccionada,
		new google.maps.Size(50,50),
		new google.maps.Point(0,0),
		new google.maps.Point(0, 50));
		var shadow = new google.maps.MarkerImage(base_url+'imagenes/iconosmapa/sombra.png',
		new google.maps.Size(100, 50),
		new google.maps.Point(0,0),
		new google.maps.Point(0, 50));
		var shape = {
			coord: [1, 1, 1, 20, 18, 20, 18 , 1],
			type: 'poly'
		};
		  var myLatLng = new google.maps.LatLng(lat,long);
		  var marker = new google.maps.Marker({
			  position: myLatLng,
			  map: map,
			  shadow: shadow,
			  icon: image,
			  shape: shape,
			  title: 'Titulo Publicidad',
		  });
	  }
	  
	  function ObtenerPosicionDeUsuario(TRuta){ 
		 if (navigator.geolocation) { // Preguntar si el navegador soporta geolocalizacion
		   navigator.geolocation.getCurrentPosition(function(position) { //obtener nuestra posicion
		   var PosicionUsuario = new google.maps.LatLng(position.coords.latitude,position.coords.longitude);
		   map.panTo(PosicionUsuario); //Mover el mapa hasta la nueva posicion geolocalizada
		   setMarkers(map,"user",position.coords.latitude,position.coords.longitude);
		   CrearRuta(PosicionUsuario,TRuta);
		   }, function() {
		    alert("No se encontro tu ubicación");
		   });
		 }
	 }
	  
	 function CrearRuta(PosicionUsuario,ModoRuta) {
		var request = {
			origin: PosicionUsuario, 
			destination: Empresalatlng,
			optimizeWaypoints: true,
			travelMode: google.maps.DirectionsTravelMode[ModoRuta]

		};
		directionsService.route(request, function(response, status) {
			if (status == google.maps.DirectionsStatus.OK) {
			  directionDisplay.setDirections(response);
			}else{
			   alert("No pudo crearse una ruta.");
			}
        });
     } 
  }
De antemano gracias

Etiquetas: google, maps
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta

SíEste tema le ha gustado a 1 personas




La zona horaria es GMT -6. Ahora son las 12:15.