	// Definición de variables comunes
	
	var map;
	var geocoder;
	var latLon;
	var myOptions;
	var directionDisplay;
  var directionsService;
	
	// Función para crear el mapa de contacto
	
	function initializeLocalizacion() {
		latLon = new google.maps.LatLng(37.175124, -3.59858);
	  myOptions = {
			zoom: 16,
		  center: latLon,
		  mapTypeId: google.maps.MapTypeId.ROADMAP}
	 	map = new google.maps.Map(document.getElementById('mapaContacto'), myOptions);
		var marker = new google.maps.Marker({
			position: latLon, 
		  map: map,
	   	icon: '../imagenes/mapas/defaul1.png'
		});
	}
	
	// Función para inicializar como llegar
	function initializeRuta(){
		directionsDisplay = new google.maps.DirectionsRenderer();
		directionsService = new google.maps.DirectionsService();
		latLon = new google.maps.LatLng(37.175124, -3.59858);	
		myOptions = {
			zoom: 16,
			center: latLon,
	  	mapTypeId: google.maps.MapTypeId.ROADMAP
  	};
		map = new google.maps.Map(document.getElementById('mapaLlegar'), myOptions);
		var marker = new google.maps.Marker({
	  	position: latLon, 
	    map: map
    	});
		geocoder = new google.maps.Geocoder(); 
		directionsDisplay.setMap(map);
  	directionsDisplay.setPanel(document.getElementById("textoRuta"));
	}
	
	// Función para codificar una ruta y llegar al destino
	function codificaRuta() {
    var address = document.getElementById("textoSalidaRuta").value;
		document.getElementById("textoSalidaRuta").value = "";
		
    var request = {
        origin: address, 
        destination:latLon,
        travelMode: google.maps.DirectionsTravelMode.DRIVING
    };
    directionsService.route(request, function(response, status) {
      if (status == google.maps.DirectionsStatus.OK) {
        directionsDisplay.setDirections(response);
      }else{
				alert("Dirección incorrecta");
			}
    });
		
  }
	
	// Ruta desde el aeropuerto
	function rutaAeropuerto(){
		
		var request = {
        origin: "Autovía A-92G/A-92G", 
        destination:latLon,
        travelMode: google.maps.DirectionsTravelMode.DRIVING
    };
    directionsService.route(request, function(response, status) {
      if (status == google.maps.DirectionsStatus.OK) {
        directionsDisplay.setDirections(response);
      }else{
				alert("Dirección incorrecta");
			}
    });
	}
	
	// Ruta desde la estación de tren
	function rutaTren(){
		
		var request = {
        origin: "Av de los Andaluces, granada", 
        destination:latLon,
        travelMode: google.maps.DirectionsTravelMode.DRIVING
    };
    directionsService.route(request, function(response, status) {
      if (status == google.maps.DirectionsStatus.OK) {
        directionsDisplay.setDirections(response);
      }else{
				alert("Dirección incorrecta");
			}
    });
	}
	
	

