lecture slides for location based services [android]

18
Accessing Location- Based services Software Development for Portable Devices BITS Pilani Goa Campus Sem I 2011-12

Upload: nehil-jain

Post on 26-Jan-2015

2.486 views

Category:

Technology


0 download

DESCRIPTION

 

TRANSCRIPT

Page 1: Lecture Slides for Location based Services [Android]

Accessing Location-Based services

Software Development for Portable Devices BITS Pilani Goa Campus

Sem I 2011-12

Page 2: Lecture Slides for Location based Services [Android]

Applications

• Mapping• Directions• Dynamic chat Application• “Geotag” your photos, tweets

CS C314 Software Development For Portable Devices 2

Page 3: Lecture Slides for Location based Services [Android]

What's common in the above?

• GPS capability of the phone• Technologies to identify your location

– GPS– Cell tower triangulation

CS C314 Software Development For Portable Devices 3

Page 4: Lecture Slides for Location based Services [Android]

Location based Services (LBS)

• Two elements of LBS:– Location manager : provides hooks to lbs– Location providers : provide current location

CS C314 Software Development For Portable Devices 4

Page 5: Lecture Slides for Location based Services [Android]

Update location in Emulator

• In DDMS view, you can set the longitude and latitude

• Lets see how.

CS C314 Software Development For Portable Devices 5

Page 6: Lecture Slides for Location based Services [Android]

Location manager

• You can :– Find available location providers– Obtain your current location– Track movement– Set proximity alerts for detecting movement into

and out of the specified areas

CS C314 Software Development For Portable Devices 6

Page 7: Lecture Slides for Location based Services [Android]

Location Providers:They know where you are hiding

• Selecting location provider– Explicitly – By specifying the name– Implicitly – By specifying the selection criteria

CS C314 Software Development For Portable Devices 7

Page 8: Lecture Slides for Location based Services [Android]

Explicit

CS C314 Software Development For Portable Devices 8

Page 9: Lecture Slides for Location based Services [Android]

User permissions

CS C314 Software Development For Portable Devices 9

Page 10: Lecture Slides for Location based Services [Android]

Finding yourself

• hasAltitude() and getAltitude() for Altitude• hasSpeed() and getSpeed() for Speed

CS C314 Software Development For Portable Devices 10

Page 11: Lecture Slides for Location based Services [Android]

On the move

• Why no getMyCurrentLocationNow() ?• Not all location providers are immediately

responsive. • How to get changes in location reflected in

your app?• Register for location updates!

CS C314 Software Development For Portable Devices 11

Page 12: Lecture Slides for Location based Services [Android]

requestLocationUpdates(String provider, long minTime, float minDistance, LocationListener listener)

• provider : name of location provider• minTime : how long, in milliseconds, before

we might request for a location update• minDistance : how far,…. in meters• Listener : name of object of locationListener

CS C314 Software Development For Portable Devices 12

Page 13: Lecture Slides for Location based Services [Android]

LocationListener

CS C314 Software Development For Portable Devices 13

These are the functions provided by the location Listeners

Page 14: Lecture Slides for Location based Services [Android]

STOP!

• When not required use removeUpdates()• If you fail to do this your app will continue

getting location updates even after all activities are closed.

CS C314 Software Development For Portable Devices 14

Page 15: Lecture Slides for Location based Services [Android]

Are we there yet?

• LocationManager offers addProximityAlert()• Registers a Pending intent• addProximityAlert (double latitude, double

longitude, float radius, long expiration, PendingIntent intent)

• In case the screen goes to sleep, checks for proximity alerts happen only once every 4 minutes.

CS C314 Software Development For Portable Devices 15

Page 16: Lecture Slides for Location based Services [Android]

parameters

• Radius: the radius of the central point of the alert region, in meters

• Expiration: time for this proximity alert, in milliseconds, or -1 to indicate no expiration

CS C314 Software Development For Portable Devices 16

Page 17: Lecture Slides for Location based Services [Android]

Thank You!

CS C314 Software Development For Portable Devices 17

Page 18: Lecture Slides for Location based Services [Android]

References• Location

http://developer.android.com/reference/android/location/Location.html

• Location Manager http://developer.android.com/reference/android/location/LocationManager.html

• Location Provider http://developer.android.com/reference/android/location/LocationProvider.html

CS C314 Software Development For Portable Devices 18