Ver Mensaje Individual
  #1 (permalink)  
Antiguo 11/11/2013, 15:52
gonzalotola
 
Fecha de Ingreso: noviembre-2013
Mensajes: 2
Antigüedad: 10 años, 5 meses
Puntos: 0
Problema para cargar mismo mapa en otro html

Hola amigos, estoy programando una plataforma de itinerarios turísticos y tengo un problema, cuando cargo otra pestaña que me lleva a otro html, lo que pasa es que tengo programado un calculador de ruta con google maps y cuando clikeo en la pestaña me lleva al otro html y se pierde la ruta trazada en la pagina anterior, quería saber como puedo hacer que cargue el mismo mapa al darle click a la otra pestaña. aquí dejo el código que estoy usando.

de antemano muchas gracias.

<meta charset="UTF-8" />
<script src="http://maps.google.com/maps/api/js?sensor=true"></script>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
<script>
function calculateRoute(from, to) {
// Center initialized to villarica
var myOptions = {
zoom: 10,
center: new google.maps.LatLng(-39.397, -70.644),
mapTypeId: google.maps.MapTypeId.ROADMAP
};
// Draw the map
var mapObject = new google.maps.Map(document.getElementById("map-canvas"), myOptions);

var directionsService = new google.maps.DirectionsService();
var directionsRequest = {
origin: from,
destination: to,
travelMode: google.maps.DirectionsTravelMode.DRIVING,
unitSystem: google.maps.UnitSystem.METRIC
};
directionsService.route(
directionsRequest,
function(response, status)
{
if (status == google.maps.DirectionsStatus.OK)
{
new google.maps.DirectionsRenderer({
map: mapObject,
directions: response
});
}
else
$("#error").append("Unable to retrieve your route<br />");
}
);
}

$(document).ready(function() {
// If the browser supports the Geolocation API
if (typeof navigator.geolocation == "undefined") {
$("#error").text("Your browser doesn't support the Geolocation API");
return;
}

$("#from-link, #to-link").click(function(event) {
event.preventDefault();
var addressId = this.id.substring(0, this.id.indexOf("-"));

navigator.geolocation.getCurrentPosition(function( position) {
var geocoder = new google.maps.Geocoder();
geocoder.geocode({
"location": new google.maps.LatLng(position.coords.latitude, position.coords.longitude)
},
function(results, status) {
if (status == google.maps.GeocoderStatus.OK)
$("#" + addressId).val(results[0].formatted_address);
else
$("#error").append("Unable to retrieve your address<br />");
});
},
function(positionError){
$("#error").append("Error: " + positionError.message + "<br />");
},
{
enableHighAccuracy: true,
timeout: 10 * 1000 // 10 seconds
});
});

$("#calculate-route").submit(function(event) {
event.preventDefault();
calculateRoute($("#from").val(), $("#to").val());
});
});
</script>