location based services - code app, level up - [dec. 2012]

24
Viktor Stojanovski Android Developer @ Seavus 12.12.2012 Location-Based Services

Upload: viktor-zuber

Post on 15-Jan-2015

725 views

Category:

Technology


0 download

DESCRIPTION

Presentation about "Location Based Services" Event: Code App, Level Up Organizer: EESTEC, FCSE Date: 12.12.2012, Skopje, Macedonia

TRANSCRIPT

Page 1: Location Based Services - Code App, Level Up - [Dec. 2012]

Viktor StojanovskiAndroid Developer @ Seavus

12.12.2012

Location-Based Services

Page 2: Location Based Services - Code App, Level Up - [Dec. 2012]

Agenda

Location API

Android permissions for Location

Location Providers

Obtain device location

Location tips

Demo code

Things to do with Location

Q&A Session

Page 3: Location Based Services - Code App, Level Up - [Dec. 2012]

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.

Page 4: Location Based Services - Code App, Level Up - [Dec. 2012]

Android permissions for Location

ACCESS_COARSE_LOCATION (NETWORK_PROVIDER)

ACCESS_FINE_LOCATION (GPS_PROVIDER)

Page 5: Location Based Services - Code App, Level Up - [Dec. 2012]

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.

Page 6: Location Based Services - Code App, Level Up - [Dec. 2012]

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.

Page 7: Location Based Services - Code App, Level Up - [Dec. 2012]

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.

Page 8: Location Based Services - Code App, Level Up - [Dec. 2012]

How to obtain device location?

Page 9: Location Based Services - Code App, Level Up - [Dec. 2012]

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

Page 10: Location Based Services - Code App, Level Up - [Dec. 2012]

Location Criteria

Page 11: Location Based Services - Code App, Level Up - [Dec. 2012]

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.

Page 12: Location Based Services - Code App, Level Up - [Dec. 2012]

Fresh location informationIterate through each location provider on the device:

Find the most timely and accurate last known location

Page 13: Location Based Services - Code App, Level Up - [Dec. 2012]

Verify the Location Provider is Enabled

Page 14: Location Based Services - Code App, Level Up - [Dec. 2012]

Get device location Flow

Criteria Provider Location Manager Location Listener

- Power- Accuracy

Best provider by criteria- Last Known Location- onLocationChanged

Update user data

Page 15: Location Based Services - Code App, Level Up - [Dec. 2012]

Demo Code - MyLocation

Page 16: Location Based Services - Code App, Level Up - [Dec. 2012]

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.

Page 17: Location Based Services - Code App, Level Up - [Dec. 2012]

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

Page 18: Location Based Services - Code App, Level Up - [Dec. 2012]

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)

Page 19: Location Based Services - Code App, Level Up - [Dec. 2012]

Someone has already done it. Use it!

https://developers.google.com/places/

https://developer.foursquare.com/

Page 20: Location Based Services - Code App, Level Up - [Dec. 2012]

Google Places API – Nearby Search

Place Searches

Nearby Search Requests

Text Search Requests

Place Details

Place Actions

Places Autocomplete

Output: either JSON or XML

Page 21: Location Based Services - Code App, Level Up - [Dec. 2012]

Foursqaure API

Search for venues

Addresses

Popularity

Tips

Photos

Access recommendations

Example: https://github.com/jomartigcal/lbs-android-sample

Page 22: Location Based Services - Code App, Level Up - [Dec. 2012]
Page 23: Location Based Services - Code App, Level Up - [Dec. 2012]

Read more …

Chapter 13 Chapter 22

Page 24: Location Based Services - Code App, Level Up - [Dec. 2012]