Presentation is loading. Please wait.

Presentation is loading. Please wait.

EEC-492/693/793 iPhone Application Development

Similar presentations


Presentation on theme: "EEC-492/693/793 iPhone Application Development"— Presentation transcript:

1 EEC-492/693/793 iPhone Application Development
Lecture 17 Wenbing Zhao & Nigamanth Sridhar 11/19/2018 EEC492/693/793 - iPhone Application Development

2 Outline Maps and Locations Assignment:
Build the set of apps in the handout Note: Please do not use “Maps” as the name for the maps app if you want to test it on an i-device, because doing so would overwrite the build-in Maps app!!! 11/19/2018 11/19/2018 EEC492/693/793 - iPhone Application Development EEC492/693/793 - iPhone Application Development 2

3 Core Location Framework
Classes CLLocationManager CLLocation CLHeading Protocol CLLocationManagerDelegate No UI 11/19/2018 EEC492/693/793 - iPhone Application Development

4 How to Obtain Location Information
Three tiered approach GPS Wifi Cell network 11/19/2018 EEC492/693/793 - iPhone Application Development

5 EEC492/693/793 - iPhone Application Development
CLLocation An object to represent a point and vector in the real world @property CLLocationCoordinate2D coordinate; @property CLLocationDistance altitude; @property CLLocationAccuracy horizontalAccuracy; @property CLLocationAccuracy verticalAccuracy; @property CLLocationDirection course; @property CLLocationSpeed speed; - (NSDate *)timeStamp; - (CLLocationDistance)distanceFromLocation:(CLLocation *)location 11/19/2018 EEC492/693/793 - iPhone Application Development

6 EEC492/693/793 - iPhone Application Development
CLLocationManager Your entry point to the location service @property CLLocation *location; @property id <CLLocationManagerDelegate> delegate; @property CLLocationDistance distanceFilter; @property CLLocationAccuracy verticalAccuracy; - (void)startUpdatingLocation - (void)stopUpdatingLocation - (void)startUpdatingHeading - (void)stopUpdatingHeading 11/19/2018 EEC492/693/793 - iPhone Application Development

7 Core Location Framework: CLLocationManagerDelegate protocol
Callbacks for location change - (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation; Callbacks for heading change didUpdateHeading:(CLHeading *)newHeading; Error handling didFailLoadWithError:(NSError *)error; 11/19/2018 EEC492/693/793 - iPhone Application Development

8 Getting a Location: Starting the location service
CLLocationManager* locManager = [[CLLocationManager alloc] init]; locManager.delegate = self; [locManager startUpdatingLocation]; 11/19/2018 EEC492/693/793 - iPhone Application Development

9 Getting a Location: Using the event data
- (void)locationManager:(CLLocationManager*)manager didUpdateToLocation:(CLLocation*)newLocation fromLocation:(CLLocation*)oldLocation { NSTimeInterval howRecent = [newLocation.timestamp timeIntervalSinceNow]; if (howRecent < -10) return; if (newLocation.horizontalAccuracy > 100) return; // Use the coordinate data. double lat = newLocation.coordinate.latitude; double lon = newLocation.coordinate.longitude; } 11/19/2018 EEC492/693/793 - iPhone Application Development

10 Getting a Location: Using the event data
- (void)locationManager:(CLLocationManager *)manager didUpdateHeading:(CLHeading *)newHeading { // Use the coordinate data CLLocationDirection heading = newHeading.trueHeading; } 11/19/2018 EEC492/693/793 - iPhone Application Development

11 Desired Accuracy: Choosing an Appropriate Accuracy Level
Choose an appropriate accuracy level Higher accuracy impacts power consumption Lower accuracy is “good enough” in most cases Can change accuracy setting later if needed Actual accuracy reported in CLLocation object CLLocationManager* locManager = [[CLLocationManager alloc] init]; locManager.desiredAccuracy = kCLLocationAccuracyBest; 11/19/2018 EEC492/693/793 - iPhone Application Development

12 Distance Filter Choosing an appropriate update threshold
New events delivered when threshold exceeded CLLocationManager* locManager = [[CLLocationManager alloc] init]; locManager.distanceFilter = 3000; // in meters 11/19/2018 EEC492/693/793 - iPhone Application Development

13 EEC492/693/793 - iPhone Application Development
Stopping the Service CLLocationManager* locManager = [[CLLocationManager alloc] init]; [locManager startUpdatingLocation]; ... [locManager stopUpdatingLocation]; 11/19/2018 EEC492/693/793 - iPhone Application Development

14 Responding to Errors User may deny use of the location service
Results in a kCLErrorDenied error Protects user privacy Occurs on a per-application basis 11/19/2018 EEC492/693/793 - iPhone Application Development

15 Responding to Errors Location may be unavailable
Results in a kCLErrorLocationUnknown error Likely just temporary Scan continues in background 11/19/2018 EEC492/693/793 - iPhone Application Development

16 EEC492/693/793 - iPhone Application Development
MapKit API to display Maps Classes to translate between CLLocation and human-readable addresses Support for “annotations” (pins on a map) Reverse Geocoding 11/19/2018 EEC492/693/793 - iPhone Application Development

17 EEC492/693/793 - iPhone Application Development
MKMapView Handles display of map “Map” & “Satellite” types Panning and Zooming Annotations Display User Location 11/19/2018 EEC492/693/793 - iPhone Application Development

18 EEC492/693/793 - iPhone Application Development
MKMapView Properties in MKMapView @property MKCoordinateRegion region; @property CLLocationCoordinate2D centerCoordinate; @property MKMapType mapType; @property NSArray *annotations; @property MKUserLocation userLocation; @property id <MKMapViewDelegate> delegate; 11/19/2018 EEC492/693/793 - iPhone Application Development

19 EEC492/693/793 - iPhone Application Development
MKMapViewDelegate Callback methods about loading state: - (void)mapViewWillStartLoadingMap:(MKMapView *)mapView; - (void)mapViewDidFinishLoadingMap:(MKMapView *)mapView; - (void)mapViewDidFailLoadingMap:(MKMapView *)mapView withError:(NSError *)error; Callback methods about region changes: - (void)mapView:(MKMapView *)mapView regionWillChangeAnimated:(BOOL)animated; regionDidChangeAnimated:(BOOL)animated; 11/19/2018 EEC492/693/793 - iPhone Application Development

20 EEC492/693/793 - iPhone Application Development
MKMapViewDelegate Callback methods to customize and interact with “annotations”: // return the view for the annotation - (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id <MKAnnotation>)annotation; // one or more annotation views were added to the map - (void)mapView:(MKMapView *)mapView didAddAnnotationViews:(NSArray *)views; // the user tapped one of the annotation view’s accessory buttons annotationView:(MKAnnotationView *)view calloutAccessoryControlTapped:(UIControl *)control; 11/19/2018 EEC492/693/793 - iPhone Application Development

21 EEC492/693/793 - iPhone Application Development
Map Kit Data Types MKCoordinateSpan: defines the area spanned by a map region typedef struct { CLLocationDegrees latitudeDelta; CLLocationDegrees longitudeDelta; } MKCoordinateSpan; latitudeDelta The amount of north-to-south distance (measured in degrees) to display on the map. One degree of latitude is approximately 111 kilometers (69 miles) longitudeDelta The amount of east-to-west distance (measured in degrees) to display for the map region. The number of kilometers spanned by a longitude range varies based on the current latitude. For example, one degree of longitude spans a distance of approximately 111 kilometers (69 miles) at the equator but shrinks to 0 kilometers at the poles 11/19/2018 EEC492/693/793 - iPhone Application Development

22 EEC492/693/793 - iPhone Application Development
Map Kit Data Types MKCoordinateRegion: defines which portion of the map to display typedef struct { CLLocationCoordinate2D center; MKCoordinateSpan span; } MKCoordinateRegion; center The center point of the region span The horizontal and vertical span representing the amount of map to display The span also defines the current zoom level used by the map view object 11/19/2018 EEC492/693/793 - iPhone Application Development

23 EEC492/693/793 - iPhone Application Development
MKAnnotation MKAnnotation is - not Add to a MapView to plot pins @property CLLocationCoordinate2D coordinate; @property NSString *title; @property NSString *subtitle; 11/19/2018 EEC492/693/793 - iPhone Application Development

24 EEC492/693/793 - iPhone Application Development
MKAnnotationView View for displaying a “callout” above a map pin -(void)initWithAnnotation:(id <MKAnnotation>)annotation reuseIdentifier:(NSString *)reuseIdentifier; @property UIImage *image; @property UIView *leftCalloutAccessoryView; 11/19/2018 EEC492/693/793 - iPhone Application Development

25 EEC492/693/793 - iPhone Application Development
MKPinAnnotationView A subclass of MKAnnotationView Displays a pin icon @property BOOL animatesDrop @property MKPinAnnotationColor pinColor enum { MKPinAnnotationColorRed = 0, MKPinAnnotationColorGreen, MKPinAnnotationColorPurple }; typedef NSUInteger MKPinAnnotationColor; 11/19/2018 EEC492/693/793 - iPhone Application Development

26 EEC492/693/793 - iPhone Application Development
MKPlacemark Conforms to MKAnnotation protocol Convenience for holding human-readable addresses alongside Coordinate - (void)initWithCoordinate:(CLLocationCoordinate2D *)coordinate addressDictionary:(NSDictionary *)dictionary; Easy to convert between AddressBook addresses and location: thoroughfare, subThoroughfare, locality, subLocality, administrativeArea, subAdministrativeArea, postalCode, country, countryCode 11/19/2018 EEC492/693/793 - iPhone Application Development

27 EEC492/693/793 - iPhone Application Development
MKUserLocation Special case of an MKAnnotation Represents device’s location only @property BOOL updating (getter = isUpdating); @property CLLocation *location; @property NSString *title; @property NSString *subtitle; 11/19/2018 EEC492/693/793 - iPhone Application Development

28 EEC492/693/793 - iPhone Application Development
MKReverseGeocoder Given a location, what’s the human-readable address? - (void)initWithCoordinate:(CLLocationCoordinate2D)coordinate; @property id <MKReverseGeocoderDelegate> delegate; - (void)start; - (void)cancel; Delegate callbacks: - (void)reverseGeocoder:(MKReverseGeocoder *)geocoder didFindPlacemark:(MKPlacemark *)placemark; didFailWithError:(NSError *)error; 11/19/2018 EEC492/693/793 - iPhone Application Development


Download ppt "EEC-492/693/793 iPhone Application Development"

Similar presentations


Ads by Google