Download - Geolocation in Web and Native Mobile Apps
Geolocation in Web and Mobile Apps
Aaron Parecki – Web Directions – May 2011 [email protected] – http://aaron.pk – @aaronpk
Slides and code available at
aaron.pk/unplugged11
Displaying a Map
aaron.pk/unplugged11 @aaronpk
Displaying a Map - HTML
@aaronpk aaron.pk/unplugged11
Displaying a Map - iPhone
aaron.pk/unplugged11 @aaronpk
Displaying a Map - Android
aaron.pk/unplugged11 @aaronpk
Finding the User’s Location
aaron.pk/unplugged11 @aaronpk
Browser Geolocation
! Desktop browsers use nearby wifi hotspots
! Mobile devices may use GPS or cell tower positioning
! You can also use IP lookups to get a rough location (but is usually very inaccurate)
aaron.pk/unplugged11 @aaronpk
Browser Geolocation
with Wifi
aaron.pk/unplugged11 @aaronpk
Browser Geolocation
aaron.pk/unplugged11 @aaronpk
Browser Geolocation
aaron.pk/unplugged11 @aaronpk
Finding the User’s Location using Javascript
aaron.pk/unplugged11 @aaronpk
Browser Geolocation
aaron.pk/unplugged11 @aaronpk
Browser Geolocation
! Usability problem with this approach:
! User is left with an empty page waiting for them to press “allow”
! You should do the best you can with no location, and then update your page after you get the user’s location
! Could use IP-based location to center a map somewhere that is (probably) nearby
aaron.pk/unplugged11 @aaronpk
Using SimpleGeo
aaron.pk/unplugged11 @aaronpk
Start with IP-based geolocation to quickly center the map. Update with browser-based geolocation after it’s available.
aaron.pk/unplugged11
Finding Nearby Businesses
! SimpleGeo Places
! Foursquare API
! Twitter API
! Yelp API
! Google Places API
! Many others
aaron.pk/unplugged11 @aaronpk
Place Search with Foursquare
aaron.pk/unplugged11 @aaronpk
developer.foursquare.com
Place Search with SimpleGeo
aaron.pk/unplugged11 @aaronpk
Place Search with SimpleGeo
aaron.pk/unplugged11 @aaronpk
aaron.pk/unplugged11
Finding Information About a Location
aaron.pk/unplugged11 @aaronpk
SimpleGeo Context
aaron.pk/unplugged11 @aaronpk
SimpleGeo Context
aaron.pk/unplugged11 @aaronpk
Monitoring Continuous Location
aaron.pk/unplugged11 @aaronpk
Monitoring Continuous Location in Javascript
aaron.pk/unplugged11 @aaronpk
Now go run around outside! (But keep the browser open)
Keep the browser open? That’s kind of lame.
aaron.pk/unplugged11 @aaronpk
Monitoring Continuous Location on the iPhone
aaron.pk/unplugged11 @aaronpk
This will keep running in the background! (But now you will potentially drain the battery)
Getting the User’s Approximate Location
Saving battery by
aaron.pk/unplugged11 @aaronpk
Retrieving Approximate Location on the iPhone
[locationManager startMonitoringSignificantLocationChanges];
aaron.pk/unplugged11 @aaronpk
• Your app will be re-launched in the background when the user moves “significantly”
• Most likely when they change cell towers
• Location is very rough, ~500-1500m accuracy
Retrieving Approximate Location on Android
locationManager.requestLocationUpdate( LocationManager.PASSIVE_PROVIDER, 0, 0, listener);
aaron.pk/unplugged11 @aaronpk
• Service runs in the background, gets locations when other providers or apps request location.
• Could be cell tower location, could be GPS
Location-Based Triggers
aaron.pk/unplugged11 @aaronpk
Geonotes Location-Based Reminders
aaron.pk/unplugged11 @aaronpk
Try it! aaron.pk/geonote
Trigger-Based Actions
Create triggers based on where users are.
aaron.pk/unplugged11 @aaronpk
Send a message to all users within a radius.
aaron.pk/unplugged11 @aaronpk
Notify X when you arrive at place Y
Arrived
aaron.pk/unplugged11 @aaronpk
Real-time location-based gaming aaron.pk/unplugged11 @aaronpk
aaron.pk/unplugged11 @aaronpk
mapattack.org
Hybrid Web/Native App
aaron.pk/unplugged11 @aaronpk
Web Views
Communicating Between the Web and Native Components
aaron.pk/unplugged11 @aaronpk
Communicating Between the Web and Native Components
aaron.pk/unplugged11 @aaronpk
Turning On/Off Your Lights
aaron.pk/unplugged11 @aaronpk
Geoloqi API Your Home Server
X10 SMSified.com
Your Home Lights And sending an SMS when you leave work
X10 Lamp Switch
Linux Command Line X10 Client
www.heyu.org
$ heyu on A1
aaron.pk/unplugged11 @aaronpk
aaron.pk/unplugged11 @aaronpk
Create a Layer in Geoloqi
aaron.pk/unplugged11 @aaronpk
Docs: geoloqi.org/API/layer/create
Create a Trigger in Geoloqi
aaron.pk/unplugged11 @aaronpk
Docs: geoloqi.org/API/trigger/create
Handling a Trigger from Geoloqi
aaron.pk/unplugged11 @aaronpk
Docs: geoloqi.org/Trigger_Callback
Create an SMS Number
aaron.pk/unplugged11 @aaronpk
smsified.com or tropo.com
Send an SMS
aaron.pk/unplugged11 @aaronpk
Questions? Code: aaron.pk/unplugged11 Geoloqi API: geoloqi.org/API SMS API: smsified.com
Aaron Parecki @aaronpk
aaron.pk/unplugged11 @aaronpk