Location
This presentation is the property of its rightful owner.
Sponsored Links
1 / 21

Location PowerPoint PPT Presentation


  • 86 Views
  • Uploaded on
  • Presentation posted in: General

Location. GPS. Global Positioning System At least 4 satellites typically used 3 required extra for error detection and altitude typically accurate within 20 ft high power consumption requires line of sight to satellites trilateration

Download Presentation

Location

An Image/Link below is provided (as is) to download presentation

Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.


- - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - -

Presentation Transcript


Location

Location


Location

GPS

  • Global Positioning System

    • At least 4 satellites typically used

      • 3 required

      • extra for error detection and altitude

      • typically accurate within 20 ft

      • high power consumption

      • requires line of sight to satellites

    • trilateration

      • intersection of spheres indicating distance from satellites


Other location based services lbs

Other Location Based Services (LBS)

  • Network

    • Typically associated with mobile networks

    • Towers are used in place of satellites

      • not as accurate as GPS – typically within 200 ft

      • does not consume as much power

  • Passive

    • WIFI

      • extremely fast, no additional power usage

      • lower accuracy – typically within 1 mile

      • Google maintains a location database and uses wifi signal to determine location


Components of location in android

Components of Location in Android

  • Permissions within Manifest file

  • LocationManager class

  • Location class

  • LocationListener interface


Permissions within manifest file

Permissions within Manifest file


Permissions

Permissions

  • uses-permission tags

    • children of manifest tag

    • often placed above application tag

      <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />

      allows access to GPS, network, or passive

      <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />

      only allows access to network


Locationmanager class

LocationManager class


Locationmanager

LocationManager

  • Concrete class

  • Gives access to LBS services and classes

  • Not instantiated directly

    • instantiated through the given context’s getSystemService() method

      LocationManager lm = (LocationManager)getSystemService(Context.LOCATION_SERVICE);


Locationmanager1

LocationManager

  • important methods

    • getLastKnownLocation

      • argument: desired provider

    • getBestProvider

      • arguments

        • Criteria to use (power requirement, accuracy, bearing, speed, altitude)

          • usually a default Criteria object

        • boolean value

          • true – only those available and accessible (and meet criteria)

          • false – all providers on device (and meet criteria)

      • returns String indicating the best provider

    • getProviders

      • returns List<String> of all providers, with same boolean argument as getBestProvider (no criteria argument)

    • getAllProviders

      • returns List<String> of all providers (no arguments)


Sample code

Sample code

  • Code to obtain current location

    LocationManager lm = (LocationManager)getSystemService(Context.LOCATION_SERVICE);

    String bestProvider = lm.getBestProvider(new Criteria(), true);

    Location l = lm.getLastKnownLocation(bestProvider);


Sample code1

Sample code

  • LocationManager – methods associated with Listener

    • Registering a listener

      • arguments

        • provider to use

        • minimal time interval in milliseconds

        • minimal distance changed in meters

        • LocationListener

      • examples

        • lm.requestLocationUpdates(lm.getBestProvider(new Criteria(), true), 1000, 1000, this);

        • lm.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 1000, 1000, this);

    • Unregistering a listener

      • lm.removeUpdates(this);


Location class

Location class


Location class1

Location class

  • Concrete class

  • Represents geographic location

  • Types of data in this class:

    • accuracy – in meters

    • altitude – in meters

    • bearing – degrees east of true north

    • latitude

    • longitude

    • provider

    • speed – m/s

    • timestamp – ms since 1/1/1970


Location class2

Location class

  • important methods

    • getters for data

      • getAltitude()

      • getAccuracy()

      • etc.


Sample code using current location

Sample code – Using current location

LocationManager lm = (LocationManager)getSystemService(Context.LOCATION_SERVICE);

String bestProvider = lm.getBestProvider(new Criteria(), true);

Location myLocation = lm.getLastKnownLocation(bestProvider);

if (myLocation != null) {

tvLatitude.setText(String.valueOf(myLocation.getLatitude()));

…other code using the location goes here

}

else {

…code handling inability to retrieve a location goes here

}


Locationlistener interface

LocationListener interface


Locationlistener

LocationListener

  • Interface

  • Notified by LocationManager if status changes

  • LocationManager must register with the LocationListener


Locationlistener1

LocationListener

  • 4 abstract methods

    • onLocationChanged

      • parameter is the new location

    • onProviderDisabled and onProviderEnabled

      • parameter is the provider (String)

    • onStatusChanged

      • 3 parameters

        • provider (String)

        • status of provider (int) – constants from LocationProvider class

          • OUT_OF_SERVICE

          • TEMPORARILY_UNAVAILABLE

          • AVAILABLE

        • extras (Bundle) – currently the number of satellites


Locationlistener2

LocationListener

  • Registering/Unregistering a Manager with a Listener

    • methods in LocationManager class

      • Register

        • requestLocationUpdates(provider, delay, distance, listener)

          • provider (String)

          • delay between updates (int in ms)

          • distance (float indicating minimum distance change before update)

          • listener – the LocationListener

      • Unregister

        • removeUpdates(provider)

    • take care to utilize resources effectively

      • register in onResume()

      • unregister in onPause()


Typical approach

Typical Approach

  • The main GPS Activity extends Activity and implements LocationListener

    • within this activity:

      • 4 abstract methods from LocationListener are implemented

      • LocationManager and Location classes are used as needed

      • Handle the case where the Location is null

      • onResume and onPause methods are used to handle registering and unregistering the LocationListener

    • other Activities are used as needed


Simulating locations in emulator

Simulating locations in emulator

  • DDMS (Dalvik Debug Monitor Service)

    • Perspective in Eclipse

    • Many views associated with it to monitor Android

      • Screen capture

      • Monitoring memory usage

      • Logcat

      • Mock data, calls, location

      • Other

    • In DDMS perspective, mock locations can be set in the Emulator Control view

      • manually enter longitude and latitude

      • upload .gpx or .kml files


  • Login