Taller Introductorio A: Fitit10
Taller Introductorio A: Fitit10
Taller Introductorio A: Fitit10
<script type="text/javascript"
src="http://maps.google.com/maps/api/js?
sensor=true"></script>
<script type="text/javascript">
function inicio() {
var latlng = new google.maps.LatLng(23.737970818, -99.1444178);
var opciones = {
zoom: 6,
center: latlng,
mapTypeId: google.maps.MapTypeId.HYBRID
};
var map = new google.maps.Map(document.getElementById("mapa"),
opciones);
}
</script>
Tipos de mapa:
mapTypeId:
– google.maps.MapTypeId.HYBRID
– google.maps.MapTypeId.ROADMAP
– google.maps.MapTypeId.DEFAULT
google.maps.LatLng(23.737970818,
-99.1444178);
google.maps.Map(document.getElementBy
Id("map"), myOptions);
Elementos
Mapa.
Puntos.
Cuadros de texto.
Puntos
var marker = new google.maps.Marker({
position: latlng,
map: map,
title:"Hello World!"
});
Globos de texto
var infowindow = new google.maps.InfoWindow(
{ content: "Bienvenidos a Ciudad Victoria",
size: new google.maps.Size(50,50)
});
infowindow.open(map,marker);
Escuchando eventos…
google.maps.event.addListener(map, 'click', function(event) {
var markr = new google.maps.Marker({
position: event.latLng,
map: map
});
alert(event.latLng);
});
Quitando rastros…
google.maps.event.addListener(marker, 'click', function() {
marker.setMap(null);
});
Y dijo…
// navigationControlOptions: { style:
google.maps.NavigationControlStyle.ZOOM_PAN},
// navigationControlOptions: { style:
google.maps.NavigationControlStyle.ANDROID},
// navigationControlOptions: { style:
google.maps.NavigationControlStyle.DEFAULT},
mapTypeControl: true,
// mapTypeControlOptions: {style:
google.maps.MapTypeControlStyle.DROPDOWN_ME
NU},
// mapTypeControlOptions: {style:
google.maps.MapTypeControlStyle.HORIZONTAL_B
AR},
// mapTypeControlOptions: {style:
google.maps.MapTypeControlStyle.DEFAULT},
Usando imágenes
var imagen = 'icon/restaurant.png';
google.maps.event.addListener(map, 'click', function(event) {
var markr = new google.maps.Marker({
position: event.latLng,
map: map,
icon: imagen
});
});
Y más imágenes
var imglimites = new google.maps.LatLngBounds(
new google.maps.LatLng(23.60,-99.3992),
new google.maps.LatLng(24.92,-99.009));
var imgvic = new
google.maps.GroundOverlay("http://x.org.mx/Tamaulipas.png",
imglimites);
imgvic.setMap(map);
Puntos, líneas y polígonos
var coordenadas = [
new google.maps.LatLng(18.92034818178, -99.2352695937),
new google.maps.LatLng(19.42118174529, -99.1372080321),
new google.maps.LatLng(23.73797, -99.1444)
];
rutaVuelo.setMap(map);
var coordenadas = [
new google.maps.LatLng(18.92034818178, -99.2352695937),
new google.maps.LatLng(19.42118174529, -99.1372080321),
new google.maps.LatLng(23.73797, -99.1444)
];
rutaVuelo.setMap(map);
var infor;
http://world.wildlife.adventures.googlepages.com/wildlife-
national-parks-japan.kml
Sobreponiendo geoRSS
var georssLayer = new
google.maps.KmlLayer('http://algo.com/algo.xml');
georssLayer.setMap(map);
Geocodificación
<input id="direccion" type="textbox" value="Ciudad
Victoria, México">
function initialize() {
geocodifica = new google.maps.Geocoder();
…
}
function ubica() {
var direc = document.getElementById("direccion").value;
geocodifica.geocode( { 'address': direc}, function(results, status) {
if (status == google.maps.GeocoderStatus.OK) {
map.setCenter(results[0].geometry.location);
var marker = new google.maps.Marker({
map: map,
position: results[0].geometry.location
});
} else {
alert("La geocodificación no se pudo realizar debido a: " + status);
}
});
}
Ahora al revés…
<input id="latlng" type="textbox"
value="23.73797, -99.1444">
function initialize() {
detectBrowser();
var myOptions = {
…
}
…
}
Ubicación del W3C
If (navigator.geolocation) {
bandera_soporte = true;
navigator.geolocation.getCurrentPosition(function(position) {
ubicacion = new
google.maps.LatLng(position.coords.latitude,position.coords.longitude);
contenido = “Localización encontrada gracias al W3C standard";
map.setCenter(ubicacion);
infowindow.setContent(contenido);
infowindow.setPosition(ubicacion);
infowindow.open(map);
}, function() {
nogeo(bandera_soporte);
});
}
Google Gears Geolocation
else if (google.gears) {
bandera_soporte = true;
var geo = google.gears.factory.create('beta.geolocation');
geo.getCurrentPosition(function(position) {
ubicacion = new google.maps.LatLng(position.latitude,position.longitude);
contenido = “Ubicación encontrada por Google Gears";
map.setCenter(ubicacion);
infowindow.setContent(contenido);
infowindow.setPosition(ubicacion);
infowindow.open(map);
}, function() {
nogeo(banderasoporte);
});
}
<script type="text/javascript"
src="http://code.google.com/apis/gears/gears_init.js"></script>
Si el navegador no soporta
geolocalización…
else {
banderasoporte = false;
nogeo(banderasoporte);
}
function nogeo(error) {
if (error == true) {
contenido = "Error: Falló la geolocalización";
} else {
contenido = "Error: El navegador no soporta geolocalización";
}
ubicacion = new google.maps.LatLng(23.73797081, -99.144417);
map.setCenter(ubicacion);
infowindow.setContent(contenido);
infowindow.setPosition(ubicacion);
infowindow.open(map);
}
Extra:
Bases de datos y JSP.
Otros sabores:
Enlaces
http://code.google.com/intl/es-ES/apis/maps/documentatio
n/javascript/
http://code.google.com/intl/es-ES/apis/maps/documentatio
n/javascript/reference.html
Gracias!!!
@DarkZoro
rafaponce@cenidet.edu.mx
http://rafaponce.wordpress.com