SlideShare una empresa de Scribd logo
1 de 12
Descargar para leer sin conexión
HTML5 Tips
Geolocation
Geolocation API
•  Hay más de una forma de saber donde
estas, no necesariamente se ocupa un
GPS.
•  IP, wireless network, torre de telefono, GPS
Geolocation API
•  El usuario puede decidir compartir su
ubicación con sitios de confianza.
•  Se hace usando Javascript!
Geolocation API
•  Compatibilidad Actual
Geolocation API
•  Pasos:
1.  Revisar compatibilidad
2.  Pedir permiso al usuario
3.  Ubicar!
Geolocation API
•  Compatibilidad:
if (Modernizr.geolocation) {
// esta al dia!, ver si quiere usarlo?
}
else
{
// salado el usuario , no tiene un mejor
browser..
}
Geolocation API
•  Permiso se pide automático:
if (Modernizr.geolocation) {
// esta al dia!, ver si quiere usarlo?

navigator.geolocation.getCurrentPosition(show_map);
}
else
{
// salado el usuario, no tiene un mejor browser.. Reirse del mae.
}
Esto muestra una alerta en el browser, y el usuario DEBE dar permiso.
Geolocation API
•  Si el mae no dio Permiso L:
if (Modernizr.geolocation) {
// esta al dia!, ver si quiere usarlo?
navigator.geolocation.getCurrentPosition( show_map, handle_error);
}
else
{
// salado el usuario , no tiene un mejor browser..
}
Ni modo hay que manejar errores.
Geolocation API
•  Si el mae no dio Permiso L:
function handle_error(err)
{
if (err.code == 1)
{
// user said no!
}
if (err.code == 2)
{
// No se pudo ubicar por algun error de red u otro…
}
if (err.code == 3)
{
// el famoso TimeOut …
}
}
Geolocation API
•  Si tenemos permiso y ubicación J:
function show_map(position)
{
var latitude = position.coords.latitude;
var longitude = position.coords.longitude;
// let's show a map or do something interesting!
}
Ademas, se puede tener dependiendo:
Altitutud, velocidad, vista al norte, nivel de exactitud..
Geolocation API
•  MEGA DEMO
Como?
•  Chrome uses Google Location Services.
•  Firefox on Windows uses Google Location
Services.
•  Firefox on Linux uses GPSD http://catb.org/gpsd/. I’m not sure if this
includes Android. I haven’t had a chance to
test it yet.
•  Internet Explorer 9+ uses the Microsoft
Location Service.
•  Safari on iOS uses
Apple Location Services for iPhone OS 3.2+.

Más contenido relacionado

Similar a Html5 tips

Similar a Html5 tips (15)

HTML5 Geolocalizacion
HTML5 GeolocalizacionHTML5 Geolocalizacion
HTML5 Geolocalizacion
 
Geolocalización en HTML5
Geolocalización en HTML5Geolocalización en HTML5
Geolocalización en HTML5
 
PhoneGap Basics v1.0
PhoneGap Basics v1.0PhoneGap Basics v1.0
PhoneGap Basics v1.0
 
Presentacion geolocalización
Presentacion geolocalización Presentacion geolocalización
Presentacion geolocalización
 
Html5 Java Script Apis
Html5 Java Script ApisHtml5 Java Script Apis
Html5 Java Script Apis
 
Geolocalizacion bañuelos
Geolocalizacion  bañuelosGeolocalizacion  bañuelos
Geolocalizacion bañuelos
 
Geolocalización con Software Libre
Geolocalización con Software LibreGeolocalización con Software Libre
Geolocalización con Software Libre
 
Plataforma de informacion geolocalizada para Android (Antonio Lopez Garcia)
Plataforma de informacion geolocalizada para Android (Antonio Lopez Garcia)Plataforma de informacion geolocalizada para Android (Antonio Lopez Garcia)
Plataforma de informacion geolocalizada para Android (Antonio Lopez Garcia)
 
Geolocalización con SW libre
Geolocalización con SW libreGeolocalización con SW libre
Geolocalización con SW libre
 
Usando Google Maps en tu Android App
Usando Google Maps en tu Android AppUsando Google Maps en tu Android App
Usando Google Maps en tu Android App
 
Segunda sesion
Segunda sesionSegunda sesion
Segunda sesion
 
Introducción a groovy
Introducción a groovyIntroducción a groovy
Introducción a groovy
 
SIBW - TAC - Presentación - Daniel Díaz Salas
SIBW - TAC - Presentación - Daniel Díaz SalasSIBW - TAC - Presentación - Daniel Díaz Salas
SIBW - TAC - Presentación - Daniel Díaz Salas
 
Geolocalización v2
Geolocalización v2Geolocalización v2
Geolocalización v2
 
Poniendo a drupal en el mapa
Poniendo a drupal en el mapaPoniendo a drupal en el mapa
Poniendo a drupal en el mapa
 

Html5 tips

  • 2. Geolocation API •  Hay más de una forma de saber donde estas, no necesariamente se ocupa un GPS. •  IP, wireless network, torre de telefono, GPS
  • 3. Geolocation API •  El usuario puede decidir compartir su ubicación con sitios de confianza. •  Se hace usando Javascript!
  • 5. Geolocation API •  Pasos: 1.  Revisar compatibilidad 2.  Pedir permiso al usuario 3.  Ubicar!
  • 6. Geolocation API •  Compatibilidad: if (Modernizr.geolocation) { // esta al dia!, ver si quiere usarlo? } else { // salado el usuario , no tiene un mejor browser.. }
  • 7. Geolocation API •  Permiso se pide automático: if (Modernizr.geolocation) { // esta al dia!, ver si quiere usarlo? navigator.geolocation.getCurrentPosition(show_map); } else { // salado el usuario, no tiene un mejor browser.. Reirse del mae. } Esto muestra una alerta en el browser, y el usuario DEBE dar permiso.
  • 8. Geolocation API •  Si el mae no dio Permiso L: if (Modernizr.geolocation) { // esta al dia!, ver si quiere usarlo? navigator.geolocation.getCurrentPosition( show_map, handle_error); } else { // salado el usuario , no tiene un mejor browser.. } Ni modo hay que manejar errores.
  • 9. Geolocation API •  Si el mae no dio Permiso L: function handle_error(err) { if (err.code == 1) { // user said no! } if (err.code == 2) { // No se pudo ubicar por algun error de red u otro… } if (err.code == 3) { // el famoso TimeOut … } }
  • 10. Geolocation API •  Si tenemos permiso y ubicación J: function show_map(position) { var latitude = position.coords.latitude; var longitude = position.coords.longitude; // let's show a map or do something interesting! } Ademas, se puede tener dependiendo: Altitutud, velocidad, vista al norte, nivel de exactitud..
  • 12. Como? •  Chrome uses Google Location Services. •  Firefox on Windows uses Google Location Services. •  Firefox on Linux uses GPSD http://catb.org/gpsd/. I’m not sure if this includes Android. I haven’t had a chance to test it yet. •  Internet Explorer 9+ uses the Microsoft Location Service. •  Safari on iOS uses Apple Location Services for iPhone OS 3.2+.