CS5530 Mobile/Wireless Systems Core Location Framework Yanyan - - PowerPoint PPT Presentation

cs5530 mobile wireless systems core location framework
SMART_READER_LITE
LIVE PREVIEW

CS5530 Mobile/Wireless Systems Core Location Framework Yanyan - - PowerPoint PPT Presentation

CS5530 Mobile/Wireless Systems Core Location Framework Yanyan Zhuang Department of Computer Science http://www.cs.uccs.edu/~yzhuang UC. Colorado Springs CS5530 Ref. CN5E, NT@UW, WUSTL Overview Updates: o IT will upgrade Mac OS in 138 o


slide-1
SLIDE 1
  • Ref. CN5E, NT@UW, WUSTL

CS5530

CS5530 Mobile/Wireless Systems Core Location Framework

Yanyan Zhuang

Department of Computer Science http://www.cs.uccs.edu/~yzhuang

  • UC. Colorado Springs
slide-2
SLIDE 2

Overview

  • Ref. CN5E, NT@UW, WUSTL

2 CS5530

  • Updates:
  • IT will upgrade Mac OS in 138
  • 3 iPhones, 3 iPads, 1 Apple watch
  • 2 Android phones, 2 Android tabs
  • Core Location Framework
slide-3
SLIDE 3

Core Location Framework

  • Ref. CN5E, NT@UW, WUSTL

3 CS5530

  • Where does location come from
  • iOS devices employ different techniques

} GPS, cell tower triangulation, IP address of available WiFi connections

  • Mechanism used by iOS is transparent to developer: auto

uses the most accurate solution at a given time

  • Just use the core location framework
  • Key classes: CLLocationManager and CLLocation

} Access and store location

slide-4
SLIDE 4

Location Manager Class

  • Ref. CN5E, NT@UW, WUSTL

4 CS5530

  • Core Location Framework
  • var locationManager: CLLocationManager =

CLLocationManager()

  • Location manager instance must seek permission from user
  • Location access permission
  • locationManager.requestWhenInUseAuthorization()
  • locationManager.requestAlwaysAuthorization()
slide-5
SLIDE 5

More on Permissions

  • Ref. CN5E, NT@UW, WUSTL

5 CS5530

  • locationManager.requestWhenInUseAuthorization()
  • locationManager.requestAlwaysAuthorization()
  • Each method call requires a specific key-value pair added to

Information Property List dictionary in app’s Info.plist file

  • Value must describe the reason why the app needs access

} NSLocationWhenInUseUsageDescription } NSLocationAlwaysUsageDescription

slide-6
SLIDE 6

More on Permissions

  • Ref. CN5E, NT@UW, WUSTL

6 CS5530

  • Info.plist
  • GUI
slide-7
SLIDE 7

Location Accuracy

  • Ref. CN5E, NT@UW, WUSTL

7 CS5530

  • Level of accuracy is specified via the

desiredAccuracy property of the CLLocationManager object

  • locationManager.desiredAccuracy =

kCLLocationAccuracyBest

  • The greater the accuracy the greater the drain
  • n device battery
slide-8
SLIDE 8

Location Accuracy

  • Ref. CN5E, NT@UW, WUSTL

8 CS5530

  • The greater the accuracy the greater the drain on

device battery

  • kCLLocationAccuracyBestForNavigation – highest accuracy:

intended solely for use when device is connected to power supply

  • kCLLocationAccuracyBest – The highest recommended level of

accuracy for devices running on battery power

  • kCLLocationAccuracyNearestTenMeters - Accurate to within 10m
  • kCLLocationAccuracyHundredMeters,

kCLLocationAccuracyKilometer, kCLLocationAccuracyThreeKilometers

slide-9
SLIDE 9

Configuring the Distance Filter

  • Ref. CN5E, NT@UW, WUSTL

9 CS5530

  • Location manager: report updates whenever

any changes are detected in the location

  • locationManager.startUpdatingLocation() // details later
  • distanceFilter property allows apps to specify

amount of distance the location must change before an update is triggered

  • locationManager.distanceFilter = 1500.0
slide-10
SLIDE 10

Location Manager Delegate

  • Ref. CN5E, NT@UW, WUSTL

10 CS5530

  • Location manager updates/errors result in calls

to two delegate methods

  • func locationManager(_ manager: CLLocationManager,

didUpdateLocations locations: [CLLocation]) { … }

} Each time location changes, didUpdateLocations delegate method is

called and passed as an argument an array of CLLocation objects: last

  • bject in the array containing the most recent location data
  • func locationManager(_ manager: CLLocationManager,

didFailWithError error: Error) { … }

slide-11
SLIDE 11

Starting Location Updates

  • Ref. CN5E, NT@UW, WUSTL

11 CS5530

  • After suitably configured and authorized
  • locationManager.startUpdatingLocation()
  • With each location update,

didUpdateLocations is called by the location manager and passed information about the current location

slide-12
SLIDE 12

Obtaining Location Information from CLLocation Objects

  • Ref. CN5E, NT@UW, WUSTL

12 CS5530

  • Location information is passed through to the

didUpdateLocation delegate method in the form of CLLocation objects

  • Latitude
  • Longitude
  • Horizontal Accuracy
  • Altitude
  • Altitude Accuracy
slide-13
SLIDE 13

Obtaining Location Information from CLLocation Objects

  • Ref. CN5E, NT@UW, WUSTL

13 CS5530

  • Longitude and Latitude
  • let latitude: CLLocationDistance = location.coordinate.latitude
  • let longitude: CLLocationDistance = location.coordinate.longitude
  • Accuracy
  • let verticalAccuracy: CLLocationAccuracy =

location.verticalAccuracy

  • let horizontalAccuracy: CLLocationAccuracy =

location.horizontalAccuracy

  • Altitude
  • let altitude: CLLocationDistance = location.altitude
slide-14
SLIDE 14

Getting the Current Location

  • Ref. CN5E, NT@UW, WUSTL

14 CS5530

  • Want user’s current location without the need

for continuous location updates

  • locationManager.requestLocation()
  • Identify the current location and call didUpdateLocations
  • ne time passing through the current location
  • Location updates are automatically turned off
slide-15
SLIDE 15

Calculating Distances

  • Ref. CN5E, NT@UW, WUSTL

15 CS5530

  • Distance between two CLLocation points can

be calculated by calling distance(from:) of the end location and passing through the start location as an argument

  • var distance: CLLocationDistance =

endLocation.distance(from: startLocation)

slide-16
SLIDE 16

Reverse Geocode

  • Ref. CN5E, NT@UW, WUSTL

16 CS5530

func getPlacemarkFromLocation(location: CLLocation){ CLGeocoder().reverseGeocodeLocation(location, completionHandler: {(placemarks, error) in if error {println("reverse geodcode fail: \(error)")} let pm = placemarks as [CLPlacemark] if pm.count > 0 { self.showAddPinViewController(placemarks[0] as CLPlacemark) } }) }

slide-17
SLIDE 17

Simulating a Location in Simulator

  • Ref. CN5E, NT@UW, WUSTL

17 CS5530