1 / 21

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

belita
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. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Location

  2. 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

  3. 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

  4. Components of Location in Android • Permissions within Manifest file • LocationManager class • Location class • LocationListener interface

  5. Permissions within Manifest file

  6. 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

  7. LocationManager class

  8. 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);

  9. 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)

  10. 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);

  11. 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);

  12. Location class

  13. 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

  14. Location class • important methods • getters for data • getAltitude() • getAccuracy() • etc.

  15. 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 }

  16. LocationListener interface

  17. LocationListener • Interface • Notified by LocationManager if status changes • LocationManager must register with the LocationListener

  18. 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

  19. 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()

  20. 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

  21. 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

More Related