Location-Based Services       on Android                   Jomar Tigcal       GDG DevFest Bacolod 2012              Novemb...
Jomar Tigcal● Community Manager of GDG Philippines● Mobile Apps Developer● Software Engineer at Stratpoint  Technologies, ...
Moochfood                   Moochfood      is    an                   Android     application                   that allow...
Location
Challenges● Obtaining user location can consume a lot of  battery● Getting location takes some time● Because the user loca...
android.location              Android provides a location              framework        that    your              applicat...
Android Permissions● ACCESS_COARSE_LOCATION  -> Network Provider: cell tower and Wi-Fi  signals● ACCESS_FINE_LOCATION  -> ...
Android PermissionsNote:If you are using both NETWORK_PROVIDERand GPS_PROVIDER, then you need torequest only the ACCESS_FI...
Android Location API● Location  A class representing a geographic location sensed  at a particular time.● LocationManager ...
Getting User Location                  Image Source: http://evalblog.com/2011/06/06/where-am-i/
Getting User Location● Create an instance of LocationManager  Location locationManager =  (LocationManager) this.getSystem...
Getting User Location● Start listening for location updates  locationManager.requestLocationUpdates  (LocationManager.GPS_...
Getting User Location
Getting User Location
Getting User Location
Whats next?
Commonly used APIs         Image Sources: http://developer.foursquare.com and http://thegreasywiener.com/
Google Places API (https:  //developers.google.      com/places/)
Google Places API● Place Searches return a list of Places based on  a users location or search string.● Place Details requ...
Google Places API● Places Autocomplete can be used to provide  autocomplete functionality for text-based  geographic searc...
Getting API Key● Go to Google APIs console (http://code.  google.com/apis/console)● Create an API Project● Select Services...
Places Search● Nearby Search  by location (latitude, longitude)● Text Search  by search query  (e.g. "pizza in Bacolod")
Nearby Search SyntaxSyntax:https://maps.googleapis.com/maps/api/place/nearbysearch/output?parametersOutput: Either json or...
Nearby Search Required Parameters● key  API Key● location  latitude, longitude● radius  distance in meters, maximum of 50,...
Nearby Search Optional Parameterskeyword -         contentlanguage -        language codename        -     namerankby     ...
Place Search TypesSeparated by |Examples:food     restaurant   convenience_storehospital school       grocery_or_supermark...
Example● Place Search:https://maps.googleapis.com/maps/api/place/nearbysearch/json?location=loc_here&sensor=true&radius=50...
Foursquare API (https://developer.foursquare.         com)
Foursquare APICore API: Check in, view their history, see wheretheir friends are, create tips and lists, search forand lea...
Foursquare APIMerchant Platform: Allows developers to writeapplications that help registered venue ownersmanage their four...
Foursquare Venues SearchSearch Foursquare database and findinformation including tips, photos, check-incounts, and here no...
Venues Search ParametersRequired Parameters:● ll (latitude, longitude) - users location  or● near (text) - place where to ...
Venues Search ParametersOptional Parameters:●   query - name of place to search●   limit - number of results (max is 50)● ...
Foursquare DemoHTTP Request:https://api.foursquare.com/v2/venues/search?ll=40.7,-74&oauth_token=0445ZMNU5XS4JDAURLRE3MARL2...
Foursquare Demo
Google Places API Challenge 2012http://developers.google.com/places/challenge/  Deadline: November 30, 2012
Foursquare Hack Day Philippines      http://hackday.webgeek.ph/       December 1, 2012
Resources● http://developer.android.  com/reference/android/location/package-  summary.html● http://developer.android.  co...
Questions?             Image Source: http://www.smoblog.com/
Thank you very much!
Location-Based Services       on Android                   Jomar Tigcal       GDG DevFest Bacolod 2012              Novemb...
Upcoming SlideShare
Loading in...5
×

Location-Based Services on Android

8,207

Published on

My talk at the GDG DevFest Bacolod 2012 (November 5, 2012)

Published in: Technology

Location-Based Services on Android

  1. 1. Location-Based Services on Android Jomar Tigcal GDG DevFest Bacolod 2012 November 5, 2012
  2. 2. 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 jomar@tigcal.com @jomartigcal
  3. 3. Moochfood Moochfood is an Android application that allows you to record, rate and share dining experiences. http://www.moochfood.com/
  4. 4. Location
  5. 5. 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.
  6. 6. android.location Android provides a location framework that your application can use to determine the devices location and bearing and register for updates. http://developer.android. com/reference/android/locat ion/package-summary.html
  7. 7. Android Permissions● ACCESS_COARSE_LOCATION -> Network Provider: cell tower and Wi-Fi signals● ACCESS_FINE_LOCATION -> GPS Provider
  8. 8. Android PermissionsNote:If you are using both NETWORK_PROVIDERand GPS_PROVIDER, then you need torequest only the ACCESS_FINE_LOCATIONpermission, because it includes permission forboth.
  9. 9. 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.
  10. 10. Getting User Location Image Source: http://evalblog.com/2011/06/06/where-am-i/
  11. 11. 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);
  12. 12. Getting User Location● Start listening for location updates locationManager.requestLocationUpdates (LocationManager.GPS_PROVIDER, 0, 0, locationListener);● Stop listening for location updates locationManager.removeUpdates(this);
  13. 13. Getting User Location
  14. 14. Getting User Location
  15. 15. Getting User Location
  16. 16. Whats next?
  17. 17. Commonly used APIs Image Sources: http://developer.foursquare.com and http://thegreasywiener.com/
  18. 18. Google Places API (https: //developers.google. com/places/)
  19. 19. Google Places API● Place Searches return a list of Places based on a users 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 Googles 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.
  20. 20. 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.
  21. 21. Getting API Key● Go to Google APIs console (http://code. google.com/apis/console)● Create an API Project● Select Services● Turn on Places API
  22. 22. Places Search● Nearby Search by location (latitude, longitude)● Text Search by search query (e.g. "pizza in Bacolod")
  23. 23. Nearby Search SyntaxSyntax:https://maps.googleapis.com/maps/api/place/nearbysearch/output?parametersOutput: Either json or xml
  24. 24. 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)
  25. 25. Nearby Search Optional Parameterskeyword - contentlanguage - language codename - namerankby - prominence or distance*if rankby=distance, radius should not be includedtypespagetoken
  26. 26. Place Search TypesSeparated by |Examples:food restaurant convenience_storehospital school grocery_or_supermarketMore at:https://developers.google.com/places/documentation/supported_types
  27. 27. Example● Place Search:https://maps.googleapis.com/maps/api/place/nearbysearch/json?location=loc_here&sensor=true&radius=500&key=key_here● Type=foodhttps://maps.googleapis.com/maps/api/place/nearbysearch/json?location=loc_here&sensor=true&radius=500&types=food&key=key_here
  28. 28. Foursquare API (https://developer.foursquare. com)
  29. 29. Foursquare APICore API: Check in, view their history, see wheretheir friends are, create tips and lists, search forand learn more about venues, and access specialsand recommendations.Real-time API: Venue push API notifies venuemanagers when users check in to their venues,and our user push API notifies developers whentheir users check in anywhere.
  30. 30. Foursquare APIMerchant Platform: Allows developers to writeapplications that help registered venue ownersmanage their foursquare presence andspecials.Venues Platform: Search for places and accessa wealth of information about them, includingaddresses, popularity, tips, and photos.
  31. 31. Foursquare Venues SearchSearch Foursquare database and findinformation including tips, photos, check-incounts, and here nowSyntax:https://api.foursquare.com/v2/venues/search
  32. 32. Venues Search ParametersRequired Parameters:● ll (latitude, longitude) - users location or● near (text) - place where to search● v (YYYYMMDD) indicates that the client is up to date as of the specified date
  33. 33. Venues Search ParametersOptional 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
  34. 34. Foursquare DemoHTTP Request:https://api.foursquare.com/v2/venues/search?ll=40.7,-74&oauth_token=0445ZMNU5XS4JDAURLRE3MARL222RVJITL2XBKF0CR1C2EWR&v=20121102Android Project: * Sample Android Project is available at https://github.com/jomartigcal/lbs-android- sample
  35. 35. Foursquare Demo
  36. 36. Google Places API Challenge 2012http://developers.google.com/places/challenge/ Deadline: November 30, 2012
  37. 37. Foursquare Hack Day Philippines http://hackday.webgeek.ph/ December 1, 2012
  38. 38. Resources● http://developer.android. com/reference/android/location/package- summary.html● http://developer.android. com/guide/topics/location/index.html● https://developers.google.com/places/● https://developer.foursquare.com● https://github.com/jomartigcal/lbs-android- sample
  39. 39. Questions? Image Source: http://www.smoblog.com/
  40. 40. Thank you very much!
  41. 41. Location-Based Services on Android Jomar Tigcal GDG DevFest Bacolod 2012 November 5, 2012
  1. A particular slide catching your eye?

    Clipping is a handy way to collect important slides you want to go back to later.

×