Geolocation in
  Web and Mobile Apps
   Aaron Parecki – Web Directions – May 2011
aaron@parecki.com – http://aaron.pk – @aaronpk

          Slides and code available at
            aaron.pk/unplugged11
Displaying a Map




@aaronpk                      aaron.pk/unplugged11
Displaying a Map - HTML




@aaronpk                   aaron.pk/unplugged11
Displaying a Map - iPhone




@aaronpk                    aaron.pk/unplugged11
Displaying a Map - Android




@aaronpk                   aaron.pk/unplugged11
Finding the User’s
               Location




@aaronpk                    aaron.pk/unplugged11
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)




@aaronpk                                                     aaron.pk/unplugged11
Browser
  Geolocation
   with Wifi



@aaronpk        aaron.pk/unplugged11
Browser Geolocation




@aaronpk                     aaron.pk/unplugged11
Browser Geolocation




@aaronpk                     aaron.pk/unplugged11
Finding the User’s Location
                 using Javascript




@aaronpk                           aaron.pk/unplugged11
Browser Geolocation




@aaronpk                     aaron.pk/unplugged11
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




@aaronpk                                                  aaron.pk/unplugged11
Using SimpleGeo
      Start with IP-based geolocation to quickly center the map.
      Update with browser-based geolocation after it’s available.




                       aaron.pk/unplugged11
@aaronpk                                                 aaron.pk/unplugged11
Finding Nearby Businesses
   ! SimpleGeo Places

   !   Foursquare API

   !   Twitter API

   !   Yelp API

   !   Google Places API

   !   Many others




@aaronpk                    aaron.pk/unplugged11
Place Search with Foursquare




            developer.foursquare.com
@aaronpk                               aaron.pk/unplugged11
Place Search with SimpleGeo




@aaronpk                          aaron.pk/unplugged11
Place Search with SimpleGeo




                  aaron.pk/unplugged11
@aaronpk                                 aaron.pk/unplugged11
Finding Information
            About a Location




@aaronpk                    aaron.pk/unplugged11
SimpleGeo Context




@aaronpk                       aaron.pk/unplugged11
SimpleGeo Context




@aaronpk                       aaron.pk/unplugged11
Monitoring Continuous
                 Location




@aaronpk                     aaron.pk/unplugged11
Monitoring Continuous
           Location in Javascript




               Now go run around outside!
               (But keep the browser open)

@aaronpk                                     aaron.pk/unplugged11
Keep the browser open? That’s kind of lame.




@aaronpk                                                 aaron.pk/unplugged11
Monitoring Continuous
           Location on the iPhone




             This will keep running in the background!
           (But now you will potentially drain the battery)

@aaronpk                                                 aaron.pk/unplugged11
Saving battery by

            Getting the User’s
           Approximate Location




@aaronpk                              aaron.pk/unplugged11
Retrieving Approximate
                Location on the iPhone
           [locationManager startMonitoringSignificantLocationChanges];



   •  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




@aaronpk                                                       aaron.pk/unplugged11
Retrieving Approximate
              Location on Android
           locationManager.requestLocationUpdate(
             LocationManager.PASSIVE_PROVIDER, 0, 0, listener);


   •  Service runs in the background, gets locations
      when other providers or apps request location.

   •  Could be cell tower location, could be GPS




@aaronpk                                                  aaron.pk/unplugged11
Location-Based Triggers




@aaronpk                   aaron.pk/unplugged11
Geonotes                   Try it! aaron.pk/geonote
Location-Based Reminders
@aaronpk                             aaron.pk/unplugged11
Trigger-Based
           Actions




           Create triggers
           based on where
           users are.
@aaronpk          aaron.pk/unplugged11
Send a message to all users
within a radius.
@aaronpk                  aaron.pk/unplugged11
Arrived




Notify X when you arrive at place Y

@aaronpk                       aaron.pk/unplugged11
Real-time location-based gaming
@aaronpk                     aaron.pk/unplugged11
mapattack.org




@aaronpk                   aaron.pk/unplugged11
Hybrid Web/Native App

                   Web Views




@aaronpk                       aaron.pk/unplugged11
Communicating Between the
           Web and Native Components




@aaronpk                         aaron.pk/unplugged11
Communicating Between the
           Web and Native Components




@aaronpk                         aaron.pk/unplugged11
Turning On/Off Your Lights

                    Geoloqi	
  API	
  
                                         Your	
  Home	
  
                                           Server	
  



                                              X10	
  
                   SMSified.com	
  

                                         Your	
  Home	
  
And sending an SMS when you leave work     Lights	
  

@aaronpk                                            aaron.pk/unplugged11
X10 Lamp
   Switch
   Linux Command Line X10 Client
   www.heyu.org


   $ heyu on A1




@aaronpk                           aaron.pk/unplugged11
@aaronpk   aaron.pk/unplugged11
Create a Layer in Geoloqi




                Docs: geoloqi.org/API/layer/create

@aaronpk                                             aaron.pk/unplugged11
Create a Trigger in Geoloqi




             Docs: geoloqi.org/API/trigger/create

@aaronpk                                            aaron.pk/unplugged11
Handling a Trigger from Geoloqi




           Docs: geoloqi.org/Trigger_Callback
@aaronpk                                        aaron.pk/unplugged11
Create an SMS Number




               smsified.com	
  	
  	
  or	
  	
  	
  tropo.com	
  

@aaronpk                                                            aaron.pk/unplugged11
Send an SMS




@aaronpk                 aaron.pk/unplugged11
Questions?

   Code: aaron.pk/unplugged11

   Geoloqi API: geoloqi.org/API

   SMS API: smsified.com

                 Aaron Parecki @aaronpk
@aaronpk                       aaron.pk/unplugged11

Geolocation in Web and Native Mobile Apps

  • 1.
    Geolocation in Web and Mobile Apps Aaron Parecki – Web Directions – May 2011 aaron@parecki.com – http://aaron.pk – @aaronpk Slides and code available at aaron.pk/unplugged11
  • 2.
    Displaying a Map @aaronpk aaron.pk/unplugged11
  • 3.
    Displaying a Map- HTML @aaronpk aaron.pk/unplugged11
  • 4.
    Displaying a Map- iPhone @aaronpk aaron.pk/unplugged11
  • 5.
    Displaying a Map- Android @aaronpk aaron.pk/unplugged11
  • 6.
    Finding the User’s Location @aaronpk aaron.pk/unplugged11
  • 7.
    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) @aaronpk aaron.pk/unplugged11
  • 8.
    Browser Geolocation with Wifi @aaronpk aaron.pk/unplugged11
  • 9.
    Browser Geolocation @aaronpk aaron.pk/unplugged11
  • 10.
    Browser Geolocation @aaronpk aaron.pk/unplugged11
  • 11.
    Finding the User’sLocation using Javascript @aaronpk aaron.pk/unplugged11
  • 12.
    Browser Geolocation @aaronpk aaron.pk/unplugged11
  • 13.
    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 @aaronpk aaron.pk/unplugged11
  • 14.
    Using SimpleGeo Start with IP-based geolocation to quickly center the map. Update with browser-based geolocation after it’s available. aaron.pk/unplugged11 @aaronpk aaron.pk/unplugged11
  • 15.
    Finding Nearby Businesses ! SimpleGeo Places !   Foursquare API !   Twitter API !   Yelp API !   Google Places API !   Many others @aaronpk aaron.pk/unplugged11
  • 16.
    Place Search withFoursquare developer.foursquare.com @aaronpk aaron.pk/unplugged11
  • 17.
    Place Search withSimpleGeo @aaronpk aaron.pk/unplugged11
  • 18.
    Place Search withSimpleGeo aaron.pk/unplugged11 @aaronpk aaron.pk/unplugged11
  • 19.
    Finding Information About a Location @aaronpk aaron.pk/unplugged11
  • 20.
    SimpleGeo Context @aaronpk aaron.pk/unplugged11
  • 21.
    SimpleGeo Context @aaronpk aaron.pk/unplugged11
  • 22.
    Monitoring Continuous Location @aaronpk aaron.pk/unplugged11
  • 23.
    Monitoring Continuous Location in Javascript Now go run around outside! (But keep the browser open) @aaronpk aaron.pk/unplugged11
  • 24.
    Keep the browseropen? That’s kind of lame. @aaronpk aaron.pk/unplugged11
  • 25.
    Monitoring Continuous Location on the iPhone This will keep running in the background! (But now you will potentially drain the battery) @aaronpk aaron.pk/unplugged11
  • 26.
    Saving battery by Getting the User’s Approximate Location @aaronpk aaron.pk/unplugged11
  • 27.
    Retrieving Approximate Location on the iPhone [locationManager startMonitoringSignificantLocationChanges]; •  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 @aaronpk aaron.pk/unplugged11
  • 28.
    Retrieving Approximate Location on Android locationManager.requestLocationUpdate( LocationManager.PASSIVE_PROVIDER, 0, 0, listener); •  Service runs in the background, gets locations when other providers or apps request location. •  Could be cell tower location, could be GPS @aaronpk aaron.pk/unplugged11
  • 29.
  • 30.
    Geonotes Try it! aaron.pk/geonote Location-Based Reminders @aaronpk aaron.pk/unplugged11
  • 31.
    Trigger-Based Actions Create triggers based on where users are. @aaronpk aaron.pk/unplugged11
  • 32.
    Send a messageto all users within a radius. @aaronpk aaron.pk/unplugged11
  • 33.
    Arrived Notify X whenyou arrive at place Y @aaronpk aaron.pk/unplugged11
  • 34.
  • 35.
    mapattack.org @aaronpk aaron.pk/unplugged11
  • 36.
    Hybrid Web/Native App Web Views @aaronpk aaron.pk/unplugged11
  • 37.
    Communicating Between the Web and Native Components @aaronpk aaron.pk/unplugged11
  • 38.
    Communicating Between the Web and Native Components @aaronpk aaron.pk/unplugged11
  • 39.
    Turning On/Off YourLights Geoloqi  API   Your  Home   Server   X10   SMSified.com   Your  Home   And sending an SMS when you leave work Lights   @aaronpk aaron.pk/unplugged11
  • 40.
    X10 Lamp Switch Linux Command Line X10 Client www.heyu.org $ heyu on A1 @aaronpk aaron.pk/unplugged11
  • 41.
    @aaronpk aaron.pk/unplugged11
  • 42.
    Create a Layerin Geoloqi Docs: geoloqi.org/API/layer/create @aaronpk aaron.pk/unplugged11
  • 43.
    Create a Triggerin Geoloqi Docs: geoloqi.org/API/trigger/create @aaronpk aaron.pk/unplugged11
  • 44.
    Handling a Triggerfrom Geoloqi Docs: geoloqi.org/Trigger_Callback @aaronpk aaron.pk/unplugged11
  • 45.
    Create an SMSNumber smsified.com      or      tropo.com   @aaronpk aaron.pk/unplugged11
  • 46.
    Send an SMS @aaronpk aaron.pk/unplugged11
  • 47.
    Questions? Code: aaron.pk/unplugged11 Geoloqi API: geoloqi.org/API SMS API: smsified.com Aaron Parecki @aaronpk @aaronpk aaron.pk/unplugged11