11
Android - Location Based Services

Android - Location Based Services. Google Play services facilitates adding location awareness to your app with automated location tracking Geo fencing

Embed Size (px)

Citation preview

Page 1: Android - Location Based Services. Google Play services facilitates adding location awareness to your app with automated location tracking Geo fencing

Android - Location Based Services

Page 2: Android - Location Based Services. Google Play services facilitates adding location awareness to your app with automated location tracking Geo fencing

Google Play services

facilitates adding location awareness to your app with automated • location tracking • Geo fencing• activity recognition use Location Services in your APP to get the current location get periodic location updates look up addresses

Page 3: Android - Location Based Services. Google Play services facilitates adding location awareness to your app with automated location tracking Geo fencing

Location Services

• Android gives your applications access to the location services supported by the device through classes in the android.location package.• The central component of the location framework is the

LocationManager system service, which provides APIs to determine location and bearing of the underlying device.• As with other system services, you do not instantiate a LocationManager

directly.• Request an instance from the system by calling

getSystemService(Context.LOCATION_SERVICE). The method returns a handle to a new LocationManager instance.

Page 4: Android - Location Based Services. Google Play services facilitates adding location awareness to your app with automated location tracking Geo fencing

Once your application has a LocationManager, your application is able to do three things:

• Query for the list of all LocationProviders for the last known user location.• Register/unregister for periodic updates of the user's current

location from a location provider (specified either by criteria or name).• Register/unregister for a given Intent to be fired if the device comes

within a given proximity (specified by radius in meters) of a given lat/long.

Page 5: Android - Location Based Services. Google Play services facilitates adding location awareness to your app with automated location tracking Geo fencing

• Set Up Google Play Services Download and install the Google Play services component via the SDK Manager and add the library to your project.• Specify App PermissionsApps that use location services must request location permissions.

Page 6: Android - Location Based Services. Google Play services facilitates adding location awareness to your app with automated location tracking Geo fencing

• Android offers two location permissions: ACCESS_COARSE_LOCATION and ACCESS_FINE_LOCATION.• The permission you choose determines the accuracy of the location

returned by the API.• If you specify ACCESS_COARSE_LOCATION, the API returns a location

with an accuracy approximately equivalent to a city block.• Request this permission with the uses-permission element in your

app manifest

Page 7: Android - Location Based Services. Google Play services facilitates adding location awareness to your app with automated location tracking Geo fencing
Page 8: Android - Location Based Services. Google Play services facilitates adding location awareness to your app with automated location tracking Geo fencing

• Permission tag is used to enforce a user defined permission on a component of your application.• Uses-permission tag is used to take a permission from the user for

your application.• Permission tag is used when you want other application to seek

permission from the user to use some of your application components.

Page 9: Android - Location Based Services. Google Play services facilitates adding location awareness to your app with automated location tracking Geo fencing

Challenges in Determining User Location

• Obtaining user location from a mobile device can be complicated. There are several reasons why a location reading (regardless of the source) can contain errors and be inaccurate. Some sources of error in the user location include:• Multitude of location sources GPS, Cell-ID, and Wi-Fi can each provide a clue to

users location. Determining which to use and trust is a matter of trade-offs in accuracy, speed, and battery-efficiency.• User movement Because the user location changes, you must account for

movement by re-estimating user location every so often.• Varying accuracy Location estimates coming from each location source are not

consistent in their accuracy. A location obtained 10 seconds ago from one source might be more accurate than the newest location from another or same source.

Page 10: Android - Location Based Services. Google Play services facilitates adding location awareness to your app with automated location tracking Geo fencing

Flow for obtaining user location

Page 11: Android - Location Based Services. Google Play services facilitates adding location awareness to your app with automated location tracking Geo fencing

The typical flow of procedures for obtaining the user location:

• Start application.• Sometime later, start listening for updates from desired location

providers.• Maintain a "current best estimate" of location by filtering out new,

but less accurate fixes.• Stop listening for location updates.• Take advantage of the last best location estimate.