lecture slides for location based services [android]
DESCRIPTION
TRANSCRIPT
Accessing Location-Based services
Software Development for Portable Devices BITS Pilani Goa Campus
Sem I 2011-12
Applications
• Mapping• Directions• Dynamic chat Application• “Geotag” your photos, tweets
CS C314 Software Development For Portable Devices 2
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
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
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
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
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
Explicit
CS C314 Software Development For Portable Devices 8
User permissions
CS C314 Software Development For Portable Devices 9
Finding yourself
• hasAltitude() and getAltitude() for Altitude• hasSpeed() and getSpeed() for Speed
CS C314 Software Development For Portable Devices 10
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
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
LocationListener
CS C314 Software Development For Portable Devices 13
These are the functions provided by the location Listeners
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
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
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
Thank You!
CS C314 Software Development For Portable Devices 17
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