Upload
soaring-eagle-llc
View
2.267
Download
4
Tags:
Embed Size (px)
DESCRIPTION
An introduction to HTML5 Geolocation support as well as a general overview of Geolocation and Mobile Application Development implications
Citation preview
HTML5 Geolocation
Scott Ryan March 2011HTML5 Meetup Group
AgendaGeo-location Basics
Privacy
Error Handling
Positioning
Fall-Back
Mapping
Basics
Geo-location Basics
Five MethodsCell Tower Triangulation or Trilateration
1 – X Towers Used (Accuracy Varies) ~3000m
Quick Startup and lower power consumption
No sky view required
GPS4 - X Satellites Used of 24 available
Slower startup and higher battery consumption
Sky view required
Better Accuracy ~3m
Elevation Possible
BasicsWi fi Triangulation
Requires Wi fi Access
Higher Battery Consumption
IP LookupRequires IP Access
Can be very inaccurate
A-GPSCombination of GPS and Land Based System
Altitude Accuracy
Cell Tower Techniques
CID – Cell tower Id
AOA – Angle of Arrival
TOA – Time of Arrival
TDOA – Time Difference of Arrival
RSS – Received Signal Strength
Multi path Fingerprint
OTDOA – Observed Time Difference of Arrival
U-TDOA – Uplink Time Difference Of Arrival
ExampleGoogle Maps
3 circlesOutside Circle (One tower)
Inside Circle (multiple tower)
Push Pin GPS
Google Maps
Privacy
PrivacyPrompt for every domain
Cannot bypass via code
Non modal and tab specific
Display requesting website with help
Allow, Don’t Allow and Remember
Errors are handled in the error callback
Sample Output
Error Handling
Error HandlingHandled in Error Callback
CodePERMISSION_DENIED (1)
POSITION_UNAVAILABLE (2)
TIMEOUT (3)
UNKNOWN_ERROR (0)
Message
Demo
Get PositiongetCurrentPosition(function, error_function,options)
Latitude, longitude, altitude (optional)
Accuracy
Altitude Accuracy(optional)
Heading (optional)
Speed (optional)
timestamp
OptionsJavascript object
enableHighAccuracyCan fail on some phones due to permission
Timeout (After permission is handled)
maximumAge (caching)
Sample Codefunction get_position() {
var s = document.querySelector('#status');s.innerHTML = "Checking for your location";if (Modernizr.geolocation) {
navigator.geolocation.getCurrentPosition(success_callback,error_callback);
} else {alert("No Geo-location Support. Falling
back to Gears");}
}
Sample Codefunction error_callback(positionError) {
alert("Error" + positionError.code + " Message "
+ positionError.message);}
Sample Codefunction success_callback(position) {
var latitude = position.coords.latitude;
var longitude = position.coords.longitude;
var elevation = position.coords.altitude;
var accuracy = position.coords.accuracy;
var altitudeAccuracy = position.coords.altitudeAccuracy;
var heading = position.coords.heading;
var speed = position.coords.speed;
var timestamp = position.timestamp;
}
Sample Codefunction get_accurate_position() {
if (Modernizr.geolocation) {
var options = { enableHighAccuracy:true,
timeout:20000,maximumAge:300000};
navigator.geolocation.getCurrentPosition(success_callback,
error_callback,options);
} else {
alert("No Geo-location Support. Falling back to Gears");
}
}
Demo
Sample IP DataF 39.530002
4-104.9121483
56
O 39.529999 -104.9120898
52
S 39.52988602714286
-104.91237721714286
80
A 39.5299819
-104.911786
Watch PositionSame call as getPosition
Returns a number that should be stored
Returns position when location changesDevice determines sample interval
Use number to stop watchingClearWatch(number)
Sample Codefunction watch_position() {
if (Modernizr.geolocation) {
watchNumber = navigator.geolocation.watchPosition(success_callback,error_callback);
} else {
alert("No Geo-location Support. Falling back to Gears");
}
localStorage.setItem("watch",watchNumber);
}
Sample Codefunction stop_watch(){ var watchNumber = localStorage.getItem("watch"); navigator.geolocation.clearWatch(watchNumber);}
Demo
Fallbacks
Fall Back Alternatives
Geo.js
Google Gears
IP Resolution
MappingGoogle
Yahoo
Open Street Map
Microsoft
OpenLayers
Cloudmade
Mapstraction