Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Location in Android

Location in Android

Presentation given at GDGDevFest NL 2013. Presentation about available location services in android and how to use them. Including a basic overview of how mobile devices use GPS to get your location.

Thijs Damen

October 19, 2013
Tweet

More Decks by Thijs Damen

Other Decks in Programming

Transcript

  1. What is a location? 6 We are currently at Latitude:

    52.355990; Longitude: 4.953139 Thursday, October 31, 13
  2. GPS (Global Positioning System) ‣Uses satellites ‣Slow TTFF ‣High battery

    usage ‣Good accuracy (some issues with obstruction) 9 Thursday, October 31, 13
  3. Wireless networks ‣Uses WiFi and Cellular towers ‣Fast TTFF (time

    to first fix) ‣“Low” battery usage 10 Thursday, October 31, 13
  4. Wireless networks ‣Uses WiFi and Cellular towers ‣Fast TTFF (time

    to first fix) ‣“Low” battery usage ‣“Poor” accuracy 10 Thursday, October 31, 13
  5. WiFi and cellular positioning ‣WiFi • Visible MAC addresses •

    Huge database of known WiFi locations 12 Thursday, October 31, 13
  6. WiFi and cellular positioning ‣WiFi • Visible MAC addresses •

    Huge database of known WiFi locations ‣Cellular 12 Thursday, October 31, 13
  7. WiFi and cellular positioning ‣WiFi • Visible MAC addresses •

    Huge database of known WiFi locations ‣Cellular • Signal strength 12 Thursday, October 31, 13
  8. WiFi and cellular positioning ‣WiFi • Visible MAC addresses •

    Huge database of known WiFi locations ‣Cellular • Signal strength • Bearing 12 Thursday, October 31, 13
  9. Androids location services Location Manager ‣ Available from API level

    1 ‣ Selective provider use 14 Play Services ‣ Available from API level 8 (2.2) ‣ Requires Play Store ‣ Fused providers ‣ Utilizes sensor data ‣ Single API to maintain Thursday, October 31, 13
  10. What is the location object • Accuracy • Altitude •

    Bearing • Latitude & Longitude • Provider • Speed • Time • distanceTo(Location location) • bearingTo(Location location) 15 Thursday, October 31, 13
  11. The bare basics Permissions 17 Wireless & Cellular GPS <uses-permission

    android:name="android.permission.ACCESS_COARSE_LOCATION" /> <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" /> Thursday, October 31, 13
  12. Balancing performance and accuracy Location Manager ‣ Select provider •

    Time interval • Distance filter 20 Thursday, October 31, 13
  13. Balancing performance and accuracy Location Manager ‣ Select provider •

    Time interval • Distance filter ‣ Criteria • Accuracy requirement • Power requirement 20 Thursday, October 31, 13
  14. Balancing performance and accuracy Location Manager ‣ Select provider •

    Time interval • Distance filter ‣ Criteria • Accuracy requirement • Power requirement 20 Play Services ‣ LocationRequest • Priority • Expiration duration • Expiration time • Interval • Fastest interval • Maximum number of updates • Distance filter Thursday, October 31, 13
  15. Best case scenario ‣Location Manager • Use the passive provider

    ‣Play Services • Use the ‘no-power’ priority 22 Thursday, October 31, 13
  16. Think before you code • The client is not always

    right 23 Thursday, October 31, 13
  17. Think before you code • The client is not always

    right • Meet your requirements as elegant as possible 23 Thursday, October 31, 13
  18. Think before you code • The client is not always

    right • Meet your requirements as elegant as possible • Give your users control 23 Thursday, October 31, 13
  19. Extra features ‣LocationManager • Geofencing ‣Play Services • Geofencing APIs

    • Activity recognition APIs 24 Thursday, October 31, 13
  20. Geofencing with the LocationManager ‣LocationManager.addProximityAlert(); • Uses latitude, longitude and

    radius • Triggers both on entering and exiting the given area 25 Thursday, October 31, 13
  21. Geofencing with Play Services ‣Geofence.Builder() • Transition type (enter /

    exit) • Radius (latitude, longitude and radius) • Expiration duration ‣LocationClient • addGeofences(); 26 Thursday, October 31, 13