Sensors – Part 2 SE 395/595
Location in Android LocationManager class – Configure providers and their listeners LocationListener class – Handles update of location from a provider Location class – Presentation of a location udate manifest.xml – Permissions enabled here
Location Manager Obtain a list of all providers Retrieve the best provider given some criteria Request last known location for a provider Add standard location listeners – Also NMEA listeners, provides time stamp and NMEA string – A variety of listener options exist
Provider Types GPS_PROVIDER – When enabled provides location fixes via GPS – Requires ACCESS_FINE_LOCATION PERMISSION – Extra data: number of satellites NETWORK_PROVIDER – When enabled provides location fixes via network location of available cell towers and/or access points PASSIVE_PROVIDER – Does not request provider enabled – Returns location fixes being provided to other requesting entities – Requires ACCESS_FINE_LOCATION
Location Provider Similar to Sensor class – Name, power requirements, monetary cost to use, meets criteria (more on that later), requires cell, requires network, etc. – Doesn’t really provide access to date, but really details on the system.
Location Listener onStatusChanged(String provider, int status, Bundle extras) onProviderEnabled(String provider) onProviderDisabled(String provider) onLocationChanged(location)
Registering location updates Several possible options to request one or multiple location listeners requestLocationUpdates (String provider, long minTime, float minDistance, LocationListener listener) Where, minTime – minimum time interval between updates minDistance – minimum distance between updates (meters) Listener – LocationListener to listen for these changes
Location class Stores location objects – Not just for location sensor handling getLatitude getLongitude getBearing getSpeed getTime getAccuracy() etc.
Permissions Add to manifest.xml as needed above:
References API Reference – ocation/LocationListener.html ocation/LocationListener.html – ocation/LocationManager.html ocation/LocationManager.html – ocation/Location.html ocation/Location.html