Android gps, location services, camera and sensors - Paramvir Singh
Location-Based Services on Android
-
Upload
jomar-tigcal -
Category
Technology
-
view
122 -
download
0
description
Transcript of Location-Based Services on Android
![Page 1: Location-Based Services on Android](https://reader033.fdocuments.us/reader033/viewer/2022050816/54c905954a7959c9648b4575/html5/thumbnails/1.jpg)
Location-Based Services on Android
Jomar TigcalGDG DevFest Bacolod 2012
November 5, 2012
![Page 2: Location-Based Services on Android](https://reader033.fdocuments.us/reader033/viewer/2022050816/54c905954a7959c9648b4575/html5/thumbnails/2.jpg)
Jomar Tigcal
● Community Manager of GDG Philippines● Mobile Apps Developer● Software Engineer at Stratpoint
Technologies, Inc.● One of the developers of Moochfood
http://[email protected]
@jomartigcal
![Page 3: Location-Based Services on Android](https://reader033.fdocuments.us/reader033/viewer/2022050816/54c905954a7959c9648b4575/html5/thumbnails/3.jpg)
MoochfoodMoochfood is an Android application that allows you to record, rate and share dining experiences.
http://www.moochfood.com/
![Page 4: Location-Based Services on Android](https://reader033.fdocuments.us/reader033/viewer/2022050816/54c905954a7959c9648b4575/html5/thumbnails/4.jpg)
Location
![Page 5: Location-Based Services on Android](https://reader033.fdocuments.us/reader033/viewer/2022050816/54c905954a7959c9648b4575/html5/thumbnails/5.jpg)
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.
![Page 6: Location-Based Services on Android](https://reader033.fdocuments.us/reader033/viewer/2022050816/54c905954a7959c9648b4575/html5/thumbnails/6.jpg)
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/location/package-summary.html
![Page 7: Location-Based Services on Android](https://reader033.fdocuments.us/reader033/viewer/2022050816/54c905954a7959c9648b4575/html5/thumbnails/7.jpg)
Android Permissions
● ACCESS_COARSE_LOCATION -> Network Provider: cell tower and Wi-Fi signals
● ACCESS_FINE_LOCATION-> GPS Provider
![Page 8: Location-Based Services on Android](https://reader033.fdocuments.us/reader033/viewer/2022050816/54c905954a7959c9648b4575/html5/thumbnails/8.jpg)
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.
![Page 9: Location-Based Services on Android](https://reader033.fdocuments.us/reader033/viewer/2022050816/54c905954a7959c9648b4575/html5/thumbnails/9.jpg)
Android Location API
● LocationA class representing a geographic location sensed at a particular time.
● LocationManagerThis class provides access to the system location services.
● LocationListenerInterface used for receiving notifications from the LocationManager when the location has changed.
![Page 10: Location-Based Services on Android](https://reader033.fdocuments.us/reader033/viewer/2022050816/54c905954a7959c9648b4575/html5/thumbnails/10.jpg)
Image Source: http://evalblog.com/2011/06/06/where-am-i/
Getting User Location
![Page 11: Location-Based Services on Android](https://reader033.fdocuments.us/reader033/viewer/2022050816/54c905954a7959c9648b4575/html5/thumbnails/11.jpg)
Getting User Location
● Create an instance of LocationManagerLocation locationManager = (LocationManager) this.getSystemService(Context.LOCATION_SERVICE);
● Check Location Providerfinal boolean gpsEnabled = locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER);
![Page 12: Location-Based Services on Android](https://reader033.fdocuments.us/reader033/viewer/2022050816/54c905954a7959c9648b4575/html5/thumbnails/12.jpg)
Getting User Location
● Start listening for location updateslocationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, locationListener);
● Stop listening for location updateslocationManager.removeUpdates(this);
![Page 13: Location-Based Services on Android](https://reader033.fdocuments.us/reader033/viewer/2022050816/54c905954a7959c9648b4575/html5/thumbnails/13.jpg)
Getting User Location
![Page 14: Location-Based Services on Android](https://reader033.fdocuments.us/reader033/viewer/2022050816/54c905954a7959c9648b4575/html5/thumbnails/14.jpg)
Getting User Location
![Page 15: Location-Based Services on Android](https://reader033.fdocuments.us/reader033/viewer/2022050816/54c905954a7959c9648b4575/html5/thumbnails/15.jpg)
Getting User Location
![Page 16: Location-Based Services on Android](https://reader033.fdocuments.us/reader033/viewer/2022050816/54c905954a7959c9648b4575/html5/thumbnails/16.jpg)
What's next?
![Page 17: Location-Based Services on Android](https://reader033.fdocuments.us/reader033/viewer/2022050816/54c905954a7959c9648b4575/html5/thumbnails/17.jpg)
Commonly used APIs
Image Sources: http://developer.foursquare.com and http://thegreasywiener.com/
![Page 18: Location-Based Services on Android](https://reader033.fdocuments.us/reader033/viewer/2022050816/54c905954a7959c9648b4575/html5/thumbnails/18.jpg)
Google Places API (https://developers.google.
com/places/)
![Page 19: Location-Based Services on Android](https://reader033.fdocuments.us/reader033/viewer/2022050816/54c905954a7959c9648b4575/html5/thumbnails/19.jpg)
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.
![Page 20: Location-Based Services on Android](https://reader033.fdocuments.us/reader033/viewer/2022050816/54c905954a7959c9648b4575/html5/thumbnails/20.jpg)
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.
![Page 21: Location-Based Services on Android](https://reader033.fdocuments.us/reader033/viewer/2022050816/54c905954a7959c9648b4575/html5/thumbnails/21.jpg)
Getting API Key
● Go to Google APIs console (http://code.google.com/apis/console)
● Create an API Project● Select Services● Turn on Places API
![Page 22: Location-Based Services on Android](https://reader033.fdocuments.us/reader033/viewer/2022050816/54c905954a7959c9648b4575/html5/thumbnails/22.jpg)
Places Search
● Nearby Searchby location (latitude, longitude)
● Text Searchby search query (e.g. "pizza in Bacolod")
![Page 23: Location-Based Services on Android](https://reader033.fdocuments.us/reader033/viewer/2022050816/54c905954a7959c9648b4575/html5/thumbnails/23.jpg)
Nearby Search Syntax
Syntax:https://maps.googleapis.com/maps/api/place/nearbysearch/output?parameters
Output: Either json or xml
![Page 24: Location-Based Services on Android](https://reader033.fdocuments.us/reader033/viewer/2022050816/54c905954a7959c9648b4575/html5/thumbnails/24.jpg)
Nearby Search Required Parameters
● keyAPI Key
● location latitude, longitude● radius
distance in meters, maximum of 50, 000 m● sensor (true/false)
if request came from location sensor (GPS)
![Page 25: Location-Based Services on Android](https://reader033.fdocuments.us/reader033/viewer/2022050816/54c905954a7959c9648b4575/html5/thumbnails/25.jpg)
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
![Page 26: Location-Based Services on Android](https://reader033.fdocuments.us/reader033/viewer/2022050816/54c905954a7959c9648b4575/html5/thumbnails/26.jpg)
Place Search Types
Separated by |
Examples:food restaurant convenience_storehospital school grocery_or_supermarket
More at:https://developers.google.com/places/documentation/supported_types
![Page 27: Location-Based Services on Android](https://reader033.fdocuments.us/reader033/viewer/2022050816/54c905954a7959c9648b4575/html5/thumbnails/27.jpg)
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
![Page 28: Location-Based Services on Android](https://reader033.fdocuments.us/reader033/viewer/2022050816/54c905954a7959c9648b4575/html5/thumbnails/28.jpg)
Foursquare API (https://developer.foursquare.
com)
![Page 29: Location-Based Services on Android](https://reader033.fdocuments.us/reader033/viewer/2022050816/54c905954a7959c9648b4575/html5/thumbnails/29.jpg)
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.
![Page 30: Location-Based Services on Android](https://reader033.fdocuments.us/reader033/viewer/2022050816/54c905954a7959c9648b4575/html5/thumbnails/30.jpg)
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.
![Page 31: Location-Based Services on Android](https://reader033.fdocuments.us/reader033/viewer/2022050816/54c905954a7959c9648b4575/html5/thumbnails/31.jpg)
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
![Page 32: Location-Based Services on Android](https://reader033.fdocuments.us/reader033/viewer/2022050816/54c905954a7959c9648b4575/html5/thumbnails/32.jpg)
Venues Search Parameters
Required Parameters:
● ll (latitude, longitude) - user's locationor
● near (text) - place where to search
● v (YYYYMMDD) indicates that the client is up to date as of the specified date
![Page 33: Location-Based Services on Android](https://reader033.fdocuments.us/reader033/viewer/2022050816/54c905954a7959c9648b4575/html5/thumbnails/33.jpg)
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
![Page 34: Location-Based Services on Android](https://reader033.fdocuments.us/reader033/viewer/2022050816/54c905954a7959c9648b4575/html5/thumbnails/34.jpg)
Foursquare Demo
HTTP Request:https://api.foursquare.com/v2/venues/search?ll=40.7,-74&oauth_token=0445ZMNU5XS4JDAURLRE3MARL222RVJITL2XBKF0CR1C2EWR&v=20121102
Android Project:* Sample Android Project is available at https://github.com/jomartigcal/lbs-android-sample
![Page 35: Location-Based Services on Android](https://reader033.fdocuments.us/reader033/viewer/2022050816/54c905954a7959c9648b4575/html5/thumbnails/35.jpg)
Foursquare Demo
![Page 36: Location-Based Services on Android](https://reader033.fdocuments.us/reader033/viewer/2022050816/54c905954a7959c9648b4575/html5/thumbnails/36.jpg)
Deadline: November 30, 2012
Google Places API Challenge 2012http://developers.google.com/places/challenge/
![Page 37: Location-Based Services on Android](https://reader033.fdocuments.us/reader033/viewer/2022050816/54c905954a7959c9648b4575/html5/thumbnails/37.jpg)
December 1, 2012
Foursquare Hack Day Philippineshttp://hackday.webgeek.ph/
![Page 38: Location-Based Services on Android](https://reader033.fdocuments.us/reader033/viewer/2022050816/54c905954a7959c9648b4575/html5/thumbnails/38.jpg)
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
![Page 40: Location-Based Services on Android](https://reader033.fdocuments.us/reader033/viewer/2022050816/54c905954a7959c9648b4575/html5/thumbnails/40.jpg)
Thank you very much!
![Page 41: Location-Based Services on Android](https://reader033.fdocuments.us/reader033/viewer/2022050816/54c905954a7959c9648b4575/html5/thumbnails/41.jpg)
Location-Based Services on Android
Jomar TigcalGDG DevFest Bacolod 2012
November 5, 2012