location based services - code app, level up - [dec. 2012]
DESCRIPTION
Presentation about "Location Based Services" Event: Code App, Level Up Organizer: EESTEC, FCSE Date: 12.12.2012, Skopje, MacedoniaTRANSCRIPT
Viktor StojanovskiAndroid Developer @ Seavus
12.12.2012
Location-Based Services
Agenda
Location API
Android permissions for Location
Location Providers
Obtain device location
Location tips
Demo code
Things to do with Location
Q&A Session
Android Location API
Location
A class representing a geographic location.
LocationManager
Provides access to system location services.
LocationListener
Interface used for receiveing notifications from the LocationManager when location is changed.
Android permissions for Location
ACCESS_COARSE_LOCATION (NETWORK_PROVIDER)
ACCESS_FINE_LOCATION (GPS_PROVIDER)
NETWORK_PROVIDER vs GPS_PROVIDER
You need to declare the ACCESS_COARSE_LOCATION permission if your application uses a network-based location provider only.
The more accurate GPS requires the ACCESS_FINE_LOCATION permission.
Note that declaring the ACCESS_FINE_LOCATION permission implies ACCESS_COARSE_LOCATION already.
Challenges in Determining User Location
Multitude of location sources
GPS, Cell-ID, Wi-Fi
Time
Getting user information should be fast.
Re-Estimate user location
User is moving around
Varying accuracy
Different sources for location, choose the best accuracy
Battery
Don’t kill the battery, the user needs it.
How to obtain device location?
1. Add permissions to AndroidManifest.xml
2. Get a Reference to LocationManager.
3. Define a listener (LocationListener) that responds to location updates.
4. Register the LocationListener with LocationManager to receive location updates.
5. Don’t forget to unregister the listener.
How to obtain device location?
How to obtain device location?
type of location provider
minimum time interval between location updates, in milliseconds
minimum distance between location updates, in meters
setting both to zero requests location notifications as frequently as possible
Location Criteria
Fresh location information
How to reduce the latency for getting your first location?
Use getLastKnownLocation(provider) from LocationManager.
Is it enough? Which provider should be used for this? No. All providers.
Fresh location informationIterate through each location provider on the device:
Find the most timely and accurate last known location
Verify the Location Provider is Enabled
Get device location Flow
Criteria Provider Location Manager Location Listener
- Power- Accuracy
Best provider by criteria- Last Known Location- onLocationChanged
Update user data
Demo Code - MyLocation
Once you got Location, what’s next?
1. Draw maps (Google Maps, Open Street Maps, …)
2. Use third party API’s to get data (example: Google Places, Foursqare, …)
3. Get content from some server (your server) based on device’s location, maybe you are building RSS reader that displays news based on current location.
Google Maps API
Two ways for showing device’s location Open Intent with latitude and longitude for Google
MapsStandard VIEW Intent
Embed MapActivity in your applicationGenerate API Key for your device (generate another
API Key for production)Implement everything you need with maps
Google Maps API
The API automatically handles: Access to Google Maps servers Data downloading Displaying maps Touch gestures Adding markers, polygons, overlays Change view of map: (Satellite, Terrain, Traffic,
Latitude)
Someone has already done it. Use it!
https://developers.google.com/places/
https://developer.foursquare.com/
Google Places API – Nearby Search
Place Searches
Nearby Search Requests
Text Search Requests
Place Details
Place Actions
Places Autocomplete
Output: either JSON or XML
Foursqaure API
Search for venues
Addresses
Popularity
Tips
Photos
Access recommendations
Example: https://github.com/jomartigcal/lbs-android-sample
Read more …
Chapter 13 Chapter 22