donde queremos mostrar el mapa
var map = new GMap2(document.getElementById(nombreMapa));
//centramos el mapa en una latitud y longitud deseadas
map.setCenter(new GLatLng(latitud,longitud), zoom);
map.setMapType(G_NORMAL_MAP );
//añadimos controles al mapa, para interacción con el usuario
map.addControl(new GLargeMapControl());//añadimos el control para el manejo del mapa - zoom, posición, etc.
map.addControl(new GMapTypeControl());//añadimos el control para cambiar el tipo del mapa (normal, satélite, híbrido)
map.addControl(new GOverviewMapControl());//añadimos el control minimapa
map.enableScrollWheelZoom();//Hacer zoom con la rueda
gdir=new GDirections(map, document.getElementById("directions"));
var reasons=[];
reasons[G_GEO_SUCCESS] = "Success";
reasons[G_GEO_MISSING_ADDRESS] = "Missing Address: The address was either missing or had no value.";
reasons[G_GEO_UNKNOWN_ADDRESS] = "Unknown Address: No corresponding geographic location could be found for the specified address.";
reasons[G_GEO_TOO_MANY_QUERIES] = "Too Many Queries: The daily geocoding quota for this site has been exceeded.";
reasons[G_GEO_SERVER_ERROR] = "Server error: The geocoding request could not be successfully processed.";
reasons[G_GEO_BAD_REQUEST] = "A directions request could not be successfully parsed.";
reasons[G_GEO_MISSING_QUERY] = "No query was specified in the input.";
reasons[G_GEO_UNKNOWN_DIRECTIONS] = "The GDirections object could not compute directions between the points.";
// === catch Directions errors ===
GEvent.addListener(gdir, "error", function() {
var code = gdir.getStatus().code;
var reason="Code "+code;
if (reasons[code]) {
reason = reasons[code]
}
alert("Failed to obtain directions, "+reason);
});
//creo la marca para la situación
var point;
point=new GLatLng(latitud,longitud);
marca1 = createMarker(point,'marcadorGMAPS', htmlBocadillo, point.lat(), point.lng());//es el que se va a desplegar cuando haces click
map.addOverlay(marca1);
marca1.openInfoWindowHtml(html);
}
cargado=true;
}
function loadMap(nombreMapa,latitud,longitud,zoom,htmlBocadillo,enlaceTo,enlaceFrom) {
function createMarker(point,name,txt,enlaceTo,enlaceFrom) {
var marker = new GMarker(point);
// The info window version with the "to here" form open
to_html = txt;
// The info window version with the "from here" form open
from_html = txt;
// The inactive version of the direction info
txt = txt + '
Como llegar';
GEvent.addListener(marker, "click", function() {
marker.openInfoWindowHtml(txt);
});
// save the info we need to use later for the side_bar
gmarkers = marker;
html = txt;
// add a line to the side_bar html
return marker;
}
//comprobamos si el navegador es compatible con los mapas de google
if (GBrowserIsCompatible()) {
//instanciamos un mapa con GMap, pasándole una referencia a la capa o
donde queremos mostrar el mapa
var map = new GMap2(document.getElementById(nombreMapa));
//centramos el mapa en una latitud y longitud deseadas
map.setCenter(new GLatLng(latitud,longitud), zoom);
map.setMapType(G_NORMAL_MAP );
//añadimos controles al mapa, para interacción con el usuario
map.addControl(new GLargeMapControl());//añadimos el control para el manejo del mapa - zoom, posición, etc.
map.addControl(new GMapTypeControl());//añadimos el control para cambiar el tipo del mapa (normal, satélite, híbrido)
map.addControl(new GOverviewMapControl());//añadimos el control minimapa
map.enableScrollWheelZoom();//Hacer zoom con la rueda
//creo la marca para la situación
var point;
point=new GLatLng(latitud,longitud);
marca1 = createMarker(point,'marcadorGMAPS', htmlBocadillo, enlaceTo, enlaceFrom);
map.addOverlay(marca1);
marca1.openInfoWindowHtml(html);
}
cargado=true;
}