+ All Categories

gmaps

Date post: 22-Nov-2014
Category:
Upload: okano00deleon
View: 112 times
Download: 3 times
Share this document with a friend
Popular Tags:
44
Taller introductorio a M.C. Ismael Rafael Ponce Medellín 10 de noviembre 2010 FITIT10 FITIT10
Transcript
Page 1: gmaps

Taller introductorio a

M.C. Ismael Rafael Ponce Medellín

10 de noviembre 2010FITIT10FITIT10

Page 2: gmaps
Page 3: gmaps
Page 4: gmaps

¡Hola mundo

<html><head> <title>Ejercicio</title></head><body> <div id="mapa" style="width:100%; height:100%"></div></body></html>

Page 5: gmaps

… con mapas!

<meta name="viewport" content="initial-scale=1.0, user-scalable=no" />

<script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=true"></script>

Page 6: gmaps

<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>

Page 7: gmaps

Tipos de mapa:

mapTypeId: – google.maps.MapTypeId.HYBRID– google.maps.MapTypeId.ROADMAP– google.maps.MapTypeId.DEFAULT

Page 8: gmaps

google.maps.LatLng(23.737970818, -99.1444178);

google.maps.Map(document.getElementById("map"), myOptions);

Page 9: gmaps
Page 10: gmaps

Elementos

Mapa.

Puntos.

Cuadros de texto.

Page 11: gmaps

Puntos

var marker = new google.maps.Marker({

position: latlng,

map: map,

title:"Hello World!"

});

Page 12: gmaps

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);

Page 13: gmaps
Page 14: gmaps

Escuchando eventos…

google.maps.event.addListener(map, 'click', function(event) {

var markr = new google.maps.Marker({

position: event.latLng,

map: map

});

alert(event.latLng);

});

Page 15: gmaps

Quitando rastros…

google.maps.event.addListener(marker, 'click', function() {

marker.setMap(null);

});

Page 16: gmaps

Y dijo…

google.maps.event.addListener(marker, 'click', function() {

infowindow.open(map,marker);

});

Page 17: gmaps
Page 18: gmaps

Personalizando controles

var myOptions = {

navigationControl: true,

mapTypeControl: true,

scaleControl: true,

}

Page 19: gmaps

Control de navegación

navigationControl: true,// navigationControlOptions: { style:

google.maps.NavigationControlStyle.SMALL},

// navigationControlOptions: { style: google.maps.NavigationControlStyle.ZOOM_PAN},

// navigationControlOptions: { style: google.maps.NavigationControlStyle.ANDROID},

// navigationControlOptions: { style: google.maps.NavigationControlStyle.DEFAULT},

Page 20: gmaps

mapTypeControl: true,// mapTypeControlOptions: {style:

google.maps.MapTypeControlStyle.DROPDOWN_MENU},

// mapTypeControlOptions: {style: google.maps.MapTypeControlStyle.HORIZONTAL_BAR},

// mapTypeControlOptions: {style: google.maps.MapTypeControlStyle.DEFAULT},

Page 21: gmaps

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

});

});

Page 22: gmaps

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);

Page 23: gmaps

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) ];

var rutaVuelo = new google.maps.Polyline({ path: coordenadas, strokeColor: "#FF0000", strokeOpacity: 1.0, strokeWeight: 2 });

rutaVuelo.setMap(map);

Page 24: gmaps

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) ];

var rutaVuelo = new google.maps.Polygon({ paths: coordenadas, fillColor: "#FF0000", fillOpacity: 0.35, strokeColor: "#FF0000", strokeOpacity: 1.0, strokeWeight: 2 });

rutaVuelo.setMap(map);

Page 25: gmaps

var infor;

google.maps.event.addListener(rutaVuelo, 'click', function(event) { infor = new google.maps.InfoWindow(); var vertices = rutaVuelo.getPath(); var contenido = "<b>Viaje a Victoria</b><br />"; contenido += "Clic: <br />" + event.latLng.lat() + "," +

event.latLng.lng() + "<br />"; infor.setContent(contenido); infor.setPosition(event.latLng); infor.open(map);});

Page 26: gmaps

Sobreponiendo KML

var georssLayer = new google.maps.KmlLayer('http://algo.com/un.kml');

georssLayer.setMap(map);

http://world.wildlife.adventures.googlepages.com/wildlife-national-parks-japan.kml

Page 27: gmaps

Sobreponiendo geoRSS

var georssLayer = new google.maps.KmlLayer('http://algo.com/algo.xml');

georssLayer.setMap(map);

Page 28: gmaps

Geocodificación

<input id="direccion" type="textbox" value="Ciudad Victoria, México">

<input type="button" value="Geocodifica" onclick="ubica()">

Page 29: gmaps

var geocodifica;

function initialize() {

geocodifica = new google.maps.Geocoder();

}

Page 30: gmaps

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); } }); }

Page 31: gmaps

Ahora al revés…

<input id="latlng" type="textbox" value="23.73797, -99.1444">

<input type="button" value="Geocodifica-Inversa" onclick=“geoinv()">

Page 32: gmaps

Geocodificación inversa

function geoinv() {

var input = document.getElementById("latlng").value;

var latlngStr = input.split(",",2);

var lat = parseFloat(latlngStr[0]);

var lng = parseFloat(latlngStr[1]);

var latlng = new google.maps.LatLng(lat, lng);

Page 33: gmaps

geocodifica.geocode({'latLng': latlng}, function(results, status) { if (status == google.maps.GeocoderStatus.OK) { if (results[1]) { map.setZoom(11); marker = new google.maps.Marker({ position: latlng, map: map }); infowindow.setContent(results[1].formatted_address); infowindow.open(map, marker); } else { alert("Sin resultados"); } } else { alert("La geocodificación falló debido a: " + status); } }); }

Page 34: gmaps
Page 35: gmaps

Detectando el navegador

function detectBrowser() { var useragent = navigator.userAgent; var mapdiv = document.getElementById("map"); if (useragent.indexOf('iPhone') != -1 || useragent.indexOf('Android') != -1

) { mapdiv.style.width = '100%'; mapdiv.style.height = '100%'; } else { mapdiv.style.width = '80%'; mapdiv.style.height = '60%'; }}

Page 36: gmaps

Ubicación automática

var ubicacion;

var infowindow = new google.maps.InfoWindow();

var bandera_soporte = new Boolean();

function initialize() {

detectBrowser();

var myOptions = {

}

}

Page 37: gmaps

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); }); }

Page 38: gmaps

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>

Page 39: gmaps

Si el navegador no soporta geolocalización… else {

banderasoporte = false;

nogeo(banderasoporte);

}

Page 40: gmaps

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);}

Page 41: gmaps

Extra:

Bases de datos y JSP.

Page 42: gmaps

Otros sabores:

Page 44: gmaps

Gracias!!!Gracias!!!

@[email protected]

http://rafaponce.wordpress.com


Recommended