Presentation is loading. Please wait.

Presentation is loading. Please wait.

1. 2 Android location services Determining a device’s current location Tracking device movements Proximity alerts.

Similar presentations


Presentation on theme: "1. 2 Android location services Determining a device’s current location Tracking device movements Proximity alerts."— Presentation transcript:

1 1

2 2 Android location services Determining a device’s current location Tracking device movements Proximity alerts

3 3 Android makes use of different methods to provide location information to an app. These facilities are called location providers, Each has its own unique set of strengths and weaknesses. Location providers can be used for different purposes. Global Positioning System GPS Provider GPS uses a system of satellites orbiting the planet to help a receiver determine its current location. Android location services

4 4 Each GPS satellite in the constellation continuously transmits its current position. Using the distance from multiple satellites, the GPS receiver can triangulate its current location. Drawbacks: A GPS receiver needs a clear path to a GPS satellite. Unlikely to work indoors it may take a substantial amount of time to acquire a location multipath errors and can cause the location to appear to jump from one place to another

5 5 Android has an API for controlling certain aspects of GPS data. LocationManager class contains a sendExtraCommand() method that can be used to manipulate device GPS state. Android location services

6 6 Network Provider: Provides location information using cell towers, or based on wireless network information. It requires that the Wi-Fi radio is active, The Wi-Fi radio often consumes less battery power than the GPS hardware. The device makes a query to the Google location service, which provides location data based on the Wi-Fi information. Android location services

7 7 It allows devices to acquire location information in areas where GPS cannot provide location data. Wi-Fi networks must be in range. Changes to the location of Wi-Fi access points can cause inaccuracies in the location data that is produced. Android location services

8 8 Using Cell IDs Android can use the cellular network. The cellular network is used in a similar way as Wi-Fi access points to determine device location. Android and the Google location service work together to map cell tower IDs to location data in a way that is similar to Wi-Fi data. Android location services

9 9 Determining a Device’s Current Location Knowing a device’s location enables app developers to add increased functionality to a wide range of apps. Android has a robust API to its location service. Battery life and accuracy of location data are the most important aspects.

10 10 Determining a Device’s Current Location The majority of the classes are located in the android.location package. Classes: LocationManager LocationProvider Location Criteria (for queries) Interfaces: LocationListener

11 11 Determining a Device’s Current Location Android Location Components

12 12 Determining a Device’s Current Location LocationManager The main point of entry when using the location service in Android. Tells Android when it is interested in receiving updated location and information and when it no longer wants location updates. Current state of the location system, enabled location providers, and GPS status information. The last known (cached) location of the device.

13 13 LocationProvider is an abstraction for the different sources of location information in Android. Android provides different sources of location with different characteristics. Each provider generates location data differently, they all communicate with an app the same way and provide similar data to an app in the same manner. Location class contains the quantifiable data such as latitude, longitude, and altitude. Determining a Device’s Current Location

14 14 Determining a Device’s Current Location Criteria class queries the LocationManager for location providers that contain certain characteristics. The LocationListener interface contains callback methods in reaction to changes in a device’s current location or changes in location service state. The LocationManager enables an app to register/unregister a location listener implementation that can be used to process the changes in state.

15 15 The two permissions that deal with live location data are : android.permission.ACCESS_FINE_LOCATION and android.permission.ACCESS_COARSE_LOCATION The permissions define the level of accuracy that will be provided to an app from the location service. Setting up the android manifest Determining a Device’s Current Location

16 16 Determining the appropriate location provider Determining a Device’s Current Location Multiple sources of location data in Android provide varying levels of accuracy and battery consumption. The location providers in Android are: GPS location provider Network location provider Passive location provider registering each desired location provider with the LocationManager, or by specifying attributes in a Criteria object and passing that object to the LocationManager.

17 17 Determining a Device’s Current Location The GPS location provider uses orbiting satellites and time to determine the current location of a device, and tends to produce the most accurate location data. The network location provider uses two data sources to provide a location fix: Wi-Fi network location and cell-tower location. The passive location provider allows an app to receive location information from other applications not from the LocationManager.

18 18 Accuracy versus Battery Life

19 19 The LocationListener approach is the simpler approach, but the broadcast Intent approach can offer more flexibility, especially if location update information for more than one application component. Receiving location updates

20 20 Implementing Example Application How to put all the pieces of the location API together and start getting location data CurrentLocationActivity displays the current location and contains a button that allows the user to enable/disable location providers. Once the app gets a single location, it displays some of the location details on the screen. Enable the user to see with the location service in action on an actual device and Enable the user to start getting a feel for how accurate the various location providers are.

21 21 Implementing LocationListener onLocationChanged(Location location) onProviderDisabled(String provider) onProviderEnabled(String provider) onStatusChanged(String provider, int status, Bundle extras) Methods of the Location Listener are:

22 22 abstract void onLocationChanged(Location location)

23 23

24 24 Requesting Location Updates An app cannot ask Android to provide it with on-demand location information. Apps can only request to be notified when updated location information is available. The LocationManager.requestSingleLocation() method is needed. This app uses the LocationListener approach instead of intents. The app needs a new location every time the CurrentLocationActivity is presented to the user.

25 25

26 26 Launching the Location Settings Activity The button on the screen enables the user to change location provider settings.

27 to receive location data ensure that the location provider is enabled by the user. If the user does not currently have the provider enabled, the location settings activity can be for them 27 Launching the Location Settings Activity

28 28 Next Tracking device movement Proximity alerts


Download ppt "1. 2 Android location services Determining a device’s current location Tracking device movements Proximity alerts."

Similar presentations


Ads by Google