• Share
  • Email
  • Embed
  • Like
  • Save
  • Private Content
04 geolocation
 

04 geolocation

on

  • 611 views

 

Statistics

Views

Total Views
611
Views on SlideShare
611
Embed Views
0

Actions

Likes
0
Downloads
11
Comments
0

0 Embeds 0

No embeds

Accessibility

Categories

Upload Details

Uploaded via as Adobe PDF

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

    04 geolocation 04 geolocation Presentation Transcript

    • HTML5 GEOLOCATIONWhere am I?
    • Location-aware apps and websitesare all the rage today
    • Quiz: Geolocation must be done onthe ____________a. Serverb. Browser
    • Remember how a page is delivered1. Browser 2. Serverrequests a respondspage with that page3.Browserrendersthe page
    • How does geolocation know where I am?
    • How does geolocation know where I am?
    • No, but seriously ...Google Location Services (via Skyhook Wireless)•  mac_address is the mac address of the WiFi node.•  signal_strength is current signal strength measured in dBm.•  age is the number of milliseconds since the WiFi node was detected.•  SSID is the name or ESSID of the WiFi node.GPSCell towers
    • Geolocation onlyworks with the userspermission
    • Geolocation requires these JavaScriptsteps1.  Detect if geolocation is supported2.  Request current position from the user3.  If if fails, handle the error4.  If it succeeds, do something with the coordinates
    • Use the geolocation object to determinebrowser supportif (typeof navigator.geolocation == undefined) {! alert("No geolocation");!}!else {! //Do geolocation stuff here!}!
    • Request the current location from thebrowser•  Uses the async pattern•  navigator.geolocation.getCurrentPosition(success,failure)
    • If the request fails, handle the problemfunction failure(error) {! switch(error.code) {! case 1:! alert(Permission denied); break;! case 2:! alert(Position unavailable); break;! case 3:! alert(Timed out); break;! case 4:! alert(Unknown error); break;! }!}!
    • If the request succeeds, grab the positionfrom coords.latitude and coords.longitudefunction success (pos) {! var out = "lat: " + pos.coords.latitude +
 " lon: " + pos.coords.longitude;
 console.log(out);
}!
    • The precision iscontained incoords.accuracy•  position.coords.accuracy
    • Hands on geolocation
    • Conclusion•  Geolocation can be determined with just a few lines of JavaScript•  We determine if it is supported by looking at browser.geolocation•  Get the location with geolocation.getCurrentPosition(a,b)•  Failure gives us one of four failure codes•  Location comes from position.coords.latitude and position.coords.longitude