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

Location-Based Services on Android

Location-Based Services on Android

The slides I used in my talk at the GDG DevFest Bacolod 2012 (November 5, 2012)

Avatar for Jomar Tigcal

Jomar Tigcal

November 05, 2012
Tweet

More Decks by Jomar Tigcal

Other Decks in Technology

Transcript

  1. Jomar Tigcal • Community Manager of GDG Philippines • Mobile

    Apps Developer • Software Engineer at Stratpoint Technologies, Inc. • One of the developers of Moochfood http://jomar.tigcal.com [email protected] @jomartigcal
  2. Moochfood Moochfood is an Android application that allows you to

    record, rate and share dining experiences. http://www.moochfood.com/
  3. Challenges • Obtaining user location can consume a lot of

    battery • Getting location takes some time • Because the user location changes, you must account for movement by re-estimating user location every so often. • Location estimates from each source may not be accurate.
  4. android.location Android provides a location framework that your application can

    use to determine the device's location and bearing and register for updates. http://developer.android. com/reference/android/locat ion/package-summary.html
  5. Android Permissions • ACCESS_COARSE_LOCATION -> Network Provider: cell tower and

    Wi-Fi signals • ACCESS_FINE_LOCATION -> GPS Provider
  6. Android Permissions Note: If you are using both NETWORK_PROVIDER and

    GPS_PROVIDER, then you need to request only the ACCESS_FINE_LOCATION permission, because it includes permission for both.
  7. Android Location API • Location A class representing a geographic

    location sensed at a particular time. • LocationManager This class provides access to the system location services. • LocationListener Interface used for receiving notifications from the LocationManager when the location has changed.
  8. Getting User Location • Create an instance of LocationManager Location

    locationManager = (LocationManager) this.getSystemService (Context.LOCATION_SERVICE); • Check Location Provider final boolean gpsEnabled = locationManager.isProviderEnabled (LocationManager.GPS_PROVIDER);
  9. Getting User Location • Start listening for location updates locationManager.requestLocationUpdates

    (LocationManager.GPS_PROVIDER, 0, 0, locationListener); • Stop listening for location updates locationManager.removeUpdates(this);
  10. Google Places API • Place Searches return a list of

    Places based on a user's location or search string. • Place Details requests return more detailed information about a specific Place, including user reviews. • Place Actions allow you to supplement the data in Google's Places Database with data from your application. You can schedule Events, add and remove Places, or weight Place rankings from user activity with Place Bumps.
  11. Google Places API • Places Autocomplete can be used to

    provide autocomplete functionality for text-based geographic searches, by returning Places as you type. • Query Autocomplete can be used to provide a query prediction service for text-based geographic searches, by returning suggested queries as you type.
  12. Getting API Key • Go to Google APIs console (http://code.

    google.com/apis/console) • Create an API Project • Select Services • Turn on Places API
  13. Places Search • Nearby Search by location (latitude, longitude) •

    Text Search by search query (e.g. "pizza in Bacolod")
  14. Nearby Search Required Parameters • key API Key • location

    latitude, longitude • radius distance in meters, maximum of 50, 000 m • sensor (true/false) if request came from location sensor (GPS)
  15. Nearby Search Optional Parameters keyword - content language - language

    code name - name rankby - prominence or distance *if rankby=distance, radius should not be included types pagetoken
  16. Place Search Types Separated by | Examples: food restaurant convenience_store

    hospital school grocery_or_supermarket More at: https://developers.google. com/places/documentation/supported_types
  17. Example • Place Search: https://maps.googleapis. com/maps/api/place/nearbysearch/json? location=loc_here&sensor=true&radius=500&ke y=key_here • Type=food

    https://maps.googleapis. com/maps/api/place/nearbysearch/json? location=loc_here&sensor=true&radius=500&typ es=food&key=key_here
  18. Foursquare API Core API: Check in, view their history, see

    where their friends are, create tips and lists, search for and learn more about venues, and access specials and recommendations. Real-time API: Venue push API notifies venue managers when users check in to their venues, and our user push API notifies developers when their users check in anywhere.
  19. Foursquare API Merchant Platform: Allows developers to write applications that

    help registered venue owners manage their foursquare presence and specials. Venues Platform: Search for places and access a wealth of information about them, including addresses, popularity, tips, and photos.
  20. Foursquare Venues Search Search Foursquare database and find information including

    tips, photos, check-in counts, and here now Syntax: https://api.foursquare.com/v2/venues/search
  21. Venues Search Parameters Required Parameters: • ll (latitude, longitude) -

    user's location or • near (text) - place where to search • v (YYYYMMDD) indicates that the client is up to date as of the specified date
  22. Venues Search Parameters Optional Parameters: • query - name of

    place to search • limit - number of results (max is 50) • radius - distance in meters (max is 10,000) • categoryId - comma-separated categories to limit search