intro to mapping apps

Upload: narendra239qis

Post on 02-Jun-2018

219 views

Category:

Documents


0 download

TRANSCRIPT

  • 8/11/2019 Intro to Mapping Apps

    1/41

    An introduction to

    building mapping

    applications for theiPhone and iPadDr Alasdair Allan, Babilim Light Industries

    Wednesday, 29 September 2010

  • 8/11/2019 Intro to Mapping Apps

    2/41

    Frameworks

    Core Location

    Map Kit

    Wednesday, 29 September 2010

  • 8/11/2019 Intro to Mapping Apps

    3/41

    Core Location(and the GPS)

    Wednesday, 29 September 2010

  • 8/11/2019 Intro to Mapping Apps

    4/41

    Core Location

    Abstraction layer

    Cell towers (12km falling to 1-3km)

    Skyhook wireless (approx. 100m)

    GPS (approx. 40m)

    Wednesday, 29 September 2010

  • 8/11/2019 Intro to Mapping Apps

    5/41

    Core Location

    LocationManager = [[CLLocationManageralloc] init];

    locationManager.delegate = self;

    if( locationManager.locationServicesEnabled ) {

    [locationManager startUpdatingLocation];

    } else {

    ...

    }

    Wednesday, 29 September 2010

  • 8/11/2019 Intro to Mapping Apps

    6/41

    Distance lters

    locationManager.distanceFilter = 1000; // 1km

    Wednesday, 29 September 2010

  • 8/11/2019 Intro to Mapping Apps

    7/41

    Desired accuracy

    locationManager.desiredAccuracy = kCLLocationAccuracyKilometer;

    Wednesday, 29 September 2010

  • 8/11/2019 Intro to Mapping Apps

    8/41

    Delegate methods

    - (void)locationManager:(CLLocationManager*)manager didUpdateToLocation:

    (CLLocation*)newLocation fromLocation:(CLLocation*)oldLocation {

    if( newLocation != oldLocation ) {

    ...

    }

    }

    -

    (void)locationManager:(CLLocationManager*)manager didFailWithError:

    (NSError*)error { ...

    }

    Wednesday, 29 September 2010

  • 8/11/2019 Intro to Mapping Apps

    9/41

    The Magnetometer(The Digital Compass)

    Wednesday, 29 September 2010

  • 8/11/2019 Intro to Mapping Apps

    10/41Wednesday, 29 September 2010

  • 8/11/2019 Intro to Mapping Apps

    11/41Wednesday, 29 September 2010

  • 8/11/2019 Intro to Mapping Apps

    12/41

    Core Location

    LocationManager = [[CLLocationManageralloc] init];

    locationManager.delegate = self;

    if( locationManager.locationServicesEnabled &&

    locationManager.headingAvailable) {

    [locationManager startUpdatingLocation];

    [locationManager startUpdatingHeading];

    } else {

    ...

    }

    Wednesday, 29 September 2010

  • 8/11/2019 Intro to Mapping Apps

    13/41

    Heading lters

    locationManager.headingFilter = 5; // 5 degrees

    Wednesday, 29 September 2010

  • 8/11/2019 Intro to Mapping Apps

    14/41

    Delegate method

    - (void)locationManager:(CLLocationManager*) manager

    didUpdateHeading:(CLHeading*) newHeading {

    // If the accuracy is valid, process the event.

    if (newHeading.headingAccuracy > 0) {

    CLLocationDirectiontheHeading = newHeading.magneticHeading;

    ...

    }

    }

    Wednesday, 29 September 2010

  • 8/11/2019 Intro to Mapping Apps

    15/41

    True heading

    CLLocationDirectiontrueHeading = newHeading.trueHeading;

    Wednesday, 29 September 2010

  • 8/11/2019 Intro to Mapping Apps

    16/41

    Device orientation

    Heading = X degrees

    Wednesday, 29 September 2010

  • 8/11/2019 Intro to Mapping Apps

    17/41

    Device orientation

    Heading = X + 90 degrees

    Wednesday, 29 September 2010

  • 8/11/2019 Intro to Mapping Apps

    18/41

    Device orientationfloatrealHeading = heading;

    switch(orientation) {

    caseUIDeviceOrientationPortrait:

    break;

    caseUIDeviceOrientationPortraitUpsideDown:

    realHeading = realHeading + 180.0f;

    break;

    caseUIDeviceOrientationLandscapeLeft:

    realHeading = realHeading + 90.0f;

    break;

    caseUIDeviceOrientationLandscapeRight:

    realHeading = realHeading - 90.0f;

    break;

    default:

    break;

    }

    while ( realHeading > 360.0f ) {

    realHeading = realHeading - 360.0f;

    }

    Wednesday, 29 September 2010

  • 8/11/2019 Intro to Mapping Apps

    19/41

    Calibration panel

    - (BOOL)locationManagerShouldDisplayHeadingCalibration:(CLLocationManager*)manager {

    return YES;

    }

    Wednesday, 29 September 2010

  • 8/11/2019 Intro to Mapping Apps

    20/41

    Frameworks

    Core Location

    Map Kit

    Wednesday, 29 September 2010

  • 8/11/2019 Intro to Mapping Apps

    21/41

    Frameworks

    Core Location

    Map Kit

    Wednesday, 29 September 2010

  • 8/11/2019 Intro to Mapping Apps

    22/41

    Map Kit

    Wednesday, 29 September 2010

  • 8/11/2019 Intro to Mapping Apps

    23/41

    @interfaceRootController: UIViewController {

    MKMapView*mapView;

    }

    @property(nonatomic, retain) IBOutletMKMapView*mapView;

    @end

    View Controller

    Wednesday, 29 September 2010

  • 8/11/2019 Intro to Mapping Apps

    24/41

    Interface Builder

    Wednesday, 29 September 2010

  • 8/11/2019 Intro to Mapping Apps

    25/41

    Wednesday, 29 September 2010

  • 8/11/2019 Intro to Mapping Apps

    26/41

    Delegate methods

    - (void)locationManager:(CLLocationManager*)manager didUpdateToLocation:

    (CLLocation*)newLocation fromLocation:(CLLocation*)oldLocation {

    if( newLocation != oldLocation ) {

    doublemiles = 2.0;

    doublescale = ABS(cos(2*M_PI*newLocation.coordinate.latitude/360.0));

    MKCoordinateSpanspan;

    span.latitudeDelta = miles/69.0;

    span.longitudeDelta = miles/( scale*69.0 );

    MKCoordinateRegionregion;

    region.span = span;

    region.center = newLocation.coordinate; [self.mapView setRegion:region animated:YES];

    self.mapView.showsUserLocation = YES;

    }

    }

    Wednesday, 29 September 2010

  • 8/11/2019 Intro to Mapping Apps

    27/41

    Wednesday, 29 September 2010

  • 8/11/2019 Intro to Mapping Apps

    28/41

    @interfaceSimpleAnnotation: NSObject {

    CLLocationCoordinate2Dcoordinate;

    NSString*title;

    NSString*subtitle;

    }

    @property(nonatomic, assign) CLLocationCoordinate2Dcoordinate;

    @property(nonatomic, retain) NSString*title;

    @property(nonatomic, retain) NSString*subtitle;

    - (id)initWithCoordinate:(CLLocationCoordinate2D)coord;

    @end

    MKAnnotation

    Wednesday, 29 September 2010

  • 8/11/2019 Intro to Mapping Apps

    29/41

    MKAnnotation@implementationSimpleAnnotation

    @synthesize coordinate;

    @synthesizetitle;

    @synthesize subtitle;

    - (id)initWithCoordinate:(CLLocationCoordinate2D)coord {if ( self = [super init] ) {

    self.coordinate = coord;

    }

    return self;

    }

    - (void)dealloc {

    [title release];

    [subtitle release];

    [super dealloc];

    }

    @end

    Wednesday, 29 September 2010

  • 8/11/2019 Intro to Mapping Apps

    30/41

    Adding annotations

    SimpleAnnotation *annotation = [[SimpleAnnotationalloc] initWithCoordinate:theCoords];

    annotation.title = theTitle;

    annotation.subtitle = theSubTitle;

    MKCoordinateRegionregion = { theCoords, {0.2, 0.2} };

    [mapView setRegion:region animated:NO];

    [mapView addAnnotation: annotation];

    [annotation release];

    Wednesday, 29 September 2010

  • 8/11/2019 Intro to Mapping Apps

    31/41

    Wednesday, 29 September 2010

  • 8/11/2019 Intro to Mapping Apps

    32/41

  • 8/11/2019 Intro to Mapping Apps

    33/41

    Frameworks

    Core Location

    Map Kit

    Wednesday, 29 September 2010

  • 8/11/2019 Intro to Mapping Apps

    34/41

    Going Further

    Wednesday, 29 September 2010

  • 8/11/2019 Intro to Mapping Apps

    35/41

    Location SDKs

    Wednesday, 29 September 2010

  • 8/11/2019 Intro to Mapping Apps

    36/41

    Location SDKs

    Wednesday, 29 September 2010

  • 8/11/2019 Intro to Mapping Apps

    37/41

    Further Readinghttp://learningiphoneprogramming.comhttp://programmingiphonesensors.com

    Wednesday, 29 September 2010

  • 8/11/2019 Intro to Mapping Apps

    38/41

    Further Reading

    Get 35% offof the print book and

    40% offof the ebook version by

    entering discount code ABF10.

    http://learningiphoneprogramming.comhttp://programmingiphonesensors.com

    Wednesday, 29 September 2010

  • 8/11/2019 Intro to Mapping Apps

    39/41

    OReilly Masterclass

    Get 40% offby entering discount code ABF10.

    http://oreilly.com/go/location-sensors/

    Wednesday, 29 September 2010

  • 8/11/2019 Intro to Mapping Apps

    40/41

    OReilly Masterclass

    "Buy 1 video, get 1 free. Buy 2 videos, get 2

    free..." promotion all through September by

    entering discount code BVGVF.

    http://oreilly.com/go/location-sensors/

    Wednesday, 29 September 2010

    http://oreilly.com/videos/http://oreilly.com/videos/http://oreilly.com/videos/http://oreilly.com/videos/http://oreilly.com/videos/http://oreilly.com/videos/
  • 8/11/2019 Intro to Mapping Apps

    41/41

    Live Demo