Your SlideShare is downloading. ×
0
An Intro to MapKit
Rob Caporetto
@rob_caporetto
The Plan
The Plan
What is MapKit?
The Plan
What is MapKit?
Adding MapKit to your iPhone Application
The Plan
What is MapKit?
Adding MapKit to your iPhone Application
Setting the Position
The Plan
What is MapKit?
Adding MapKit to your iPhone Application
Setting the Position
Annotations
The Plan
What is MapKit?
Adding MapKit to your iPhone Application
Setting the Position
Annotations
Geocoding
The Plan
What is MapKit?
Adding MapKit to your iPhone Application
Setting the Position
Annotations
Geocoding
Interacting w...
What is MapKit?
Embed Maps in your App
Adding MapKit to your App
Adding MapKit to your App

Add the Mapkit & CoreLocation frameworks
Create a View Controller which implements
MKMapViewDel...
Setting the Position


 Set the region property
 Defines the center point and a span
 Span defines the vertical & horizontal...
Setting the Position

- (void)viewDidLoad
{
  MKCoordinateRegion region;
  region.center.latitude = [eventVenue.latitude d...
Annotations
Annotations


Allow you to add places-of-interest to a Map
Implemented with a Model & a View
Annotation Models


Implement the MKAnnotation protocol
Exposes a Title, Subtitle, and Coordinate
Title
Title   Subtitle
Title      Subtitle
Coordinate
Annotation Views


Use MKAnnotationView
Easiest trick to set the image property
Use MKPinAnnotationView if you want the Pin
Managing Annotation Views



Managed like UITableViewCells
Managing Annotation Views
- (MKAnnotationView *)mapView:(MKMapView *)theMapView
            viewForAnnotation:(id <MKAnnot...
Geocoding
Geocoding


Convert Landmarks into Longitude/Latitude
and vice-versa
SDK 3.0 Supports Reverse Geocoding only
Reverse Geocoding


Use MKReverseGeocoder
Requires network access (Wifi/3G/EDGE)
Asynchronous lookups
Interacting with Core
Location
Showing the User’s Location


Set the showsUserLocation property on the
MapView instance
Implement an Annotation
Showing the User’s Location


- (void)viewDidLoad
{
  // Other initialisation…

    mapView.showsUserLocation = YES;
}
Showing the User’s Location

- (MKAnnotationView *)mapView:(MKMapView *)theMapView
            viewForAnnotation:(id <MKAn...
Resources

WWDC 2009: Sessions 118 & 119
LocateMe Sample Application
PragProg MapKit Screencast:
  http://pragprog.com/scr...
Introduction to MapKit
Introduction to MapKit
Introduction to MapKit
Upcoming SlideShare
Loading in...5
×

Introduction to MapKit

30,298

Published on

An introductory presentation on how to use MapKit in your iPhone applications.

(From Melbourne Cocoaheads July 2009)

Published in: Technology, Spiritual
0 Comments
10 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total Views
30,298
On Slideshare
0
From Embeds
0
Number of Embeds
13
Actions
Shares
0
Downloads
405
Comments
0
Likes
10
Embeds 0
No embeds

No notes for slide
  • Introductions!
  • NOT A COMPREHENSIVE PRESENTATION, just a brief introduction to what MK is, and some of the basic things which you can do with it.

    What MapKit provides (if you didn&amp;#x2019;t catch any of the 3.0 media).
    What you need to do to support it in your iPhone application
    Setting the position of the map
    Adding &amp; Managing Annotations
    Using Core Location to be able to plot the user&amp;#x2019;s current position on screen as well
    Other hints &amp; tips
  • NOT A COMPREHENSIVE PRESENTATION, just a brief introduction to what MK is, and some of the basic things which you can do with it.

    What MapKit provides (if you didn&amp;#x2019;t catch any of the 3.0 media).
    What you need to do to support it in your iPhone application
    Setting the position of the map
    Adding &amp; Managing Annotations
    Using Core Location to be able to plot the user&amp;#x2019;s current position on screen as well
    Other hints &amp; tips
  • NOT A COMPREHENSIVE PRESENTATION, just a brief introduction to what MK is, and some of the basic things which you can do with it.

    What MapKit provides (if you didn&amp;#x2019;t catch any of the 3.0 media).
    What you need to do to support it in your iPhone application
    Setting the position of the map
    Adding &amp; Managing Annotations
    Using Core Location to be able to plot the user&amp;#x2019;s current position on screen as well
    Other hints &amp; tips
  • NOT A COMPREHENSIVE PRESENTATION, just a brief introduction to what MK is, and some of the basic things which you can do with it.

    What MapKit provides (if you didn&amp;#x2019;t catch any of the 3.0 media).
    What you need to do to support it in your iPhone application
    Setting the position of the map
    Adding &amp; Managing Annotations
    Using Core Location to be able to plot the user&amp;#x2019;s current position on screen as well
    Other hints &amp; tips
  • NOT A COMPREHENSIVE PRESENTATION, just a brief introduction to what MK is, and some of the basic things which you can do with it.

    What MapKit provides (if you didn&amp;#x2019;t catch any of the 3.0 media).
    What you need to do to support it in your iPhone application
    Setting the position of the map
    Adding &amp; Managing Annotations
    Using Core Location to be able to plot the user&amp;#x2019;s current position on screen as well
    Other hints &amp; tips
  • NOT A COMPREHENSIVE PRESENTATION, just a brief introduction to what MK is, and some of the basic things which you can do with it.

    What MapKit provides (if you didn&amp;#x2019;t catch any of the 3.0 media).
    What you need to do to support it in your iPhone application
    Setting the position of the map
    Adding &amp; Managing Annotations
    Using Core Location to be able to plot the user&amp;#x2019;s current position on screen as well
    Other hints &amp; tips
  • Added in 3.0
    Embed Google Maps in your app
    Full UX of Maps application (panning, scrolling, Views etc).
    Supports regular, satellite, hybrid maps
    Handles caching, tile loading, memory warnings, connectivity changes
  • This is a general screenshot from my App.
    Shows mapview with a single annotation &amp; callout
    Will explain full process later
  • Why CL? MK uses some of the CL types.
    Also may want to integrate CL into your app (eg. showing user&amp;#x2019;s location on a map)
  • - Region takes an MKCoordinateRegion struct
    - Centre is the latitude &amp; longitude point which define the location which is centred on screen.
    - Span defines the zoom level via the lat/long range (in degrees).
    - Check MKCoordinateSpan in the docs for how it needs to be set
    (long varies depending on the latitude).
    - Setting this will have an impact on the zoom level due to all of that
    - Can adjust the centre position without impacting zoom by setting the centerCoordinate property (takes a CLLocationCoordinate2D type)
  • - Snippet from my App
    - 1-2 init MKMapView (via code)
    - 4-8 set the centre to the location (user value), plus the zoom level. (0.5km lat)
    - 10 sets the region to our generated one
  • - Can have any number of annotations on your map
  • - Coordinate is required (as you need to have a location).
    - Title &amp; Subtitle are optional (although title is recommended).
    - T &amp; ST are used as the primary &amp; secondary labels on the default callout
  • Transcript of "Introduction to MapKit"

    1. 1. An Intro to MapKit Rob Caporetto @rob_caporetto
    2. 2. The Plan
    3. 3. The Plan What is MapKit?
    4. 4. The Plan What is MapKit? Adding MapKit to your iPhone Application
    5. 5. The Plan What is MapKit? Adding MapKit to your iPhone Application Setting the Position
    6. 6. The Plan What is MapKit? Adding MapKit to your iPhone Application Setting the Position Annotations
    7. 7. The Plan What is MapKit? Adding MapKit to your iPhone Application Setting the Position Annotations Geocoding
    8. 8. The Plan What is MapKit? Adding MapKit to your iPhone Application Setting the Position Annotations Geocoding Interacting with Core Location
    9. 9. What is MapKit?
    10. 10. Embed Maps in your App
    11. 11. Adding MapKit to your App
    12. 12. Adding MapKit to your App Add the Mapkit & CoreLocation frameworks Create a View Controller which implements MKMapViewDelegate Create an MKMapView instance and connect to the controller
    13. 13. Setting the Position Set the region property Defines the center point and a span Span defines the vertical & horizontal distance to display
    14. 14. Setting the Position - (void)viewDidLoad { MKCoordinateRegion region; region.center.latitude = [eventVenue.latitude doubleValue]; region.center.longitude = [eventVenue.longitude doubleValue]; region.span.latitudeDelta = 0.0039; region.span.longitudeDelta = 0.0034; mapView.region = region; }
    15. 15. Annotations
    16. 16. Annotations Allow you to add places-of-interest to a Map Implemented with a Model & a View
    17. 17. Annotation Models Implement the MKAnnotation protocol Exposes a Title, Subtitle, and Coordinate
    18. 18. Title
    19. 19. Title Subtitle
    20. 20. Title Subtitle Coordinate
    21. 21. Annotation Views Use MKAnnotationView Easiest trick to set the image property Use MKPinAnnotationView if you want the Pin
    22. 22. Managing Annotation Views Managed like UITableViewCells
    23. 23. Managing Annotation Views - (MKAnnotationView *)mapView:(MKMapView *)theMapView viewForAnnotation:(id <MKAnnotation>)annotation { MKPinAnnotationView *annotationView = (MKPinAnnotationView *)([theMapView dequeueReusableAnnotationViewWithIdentifier:@"annotation"]); if (annotationView == NULL) { annotationView = [[[MKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:@"annotation"] autorelease]; annotationView.canShowCallout = YES; annotationView.animatesDrop = YES; } annotationView.annotation = annotation; return annotationView; }
    24. 24. Geocoding
    25. 25. Geocoding Convert Landmarks into Longitude/Latitude and vice-versa SDK 3.0 Supports Reverse Geocoding only
    26. 26. Reverse Geocoding Use MKReverseGeocoder Requires network access (Wifi/3G/EDGE) Asynchronous lookups
    27. 27. Interacting with Core Location
    28. 28. Showing the User’s Location Set the showsUserLocation property on the MapView instance Implement an Annotation
    29. 29. Showing the User’s Location - (void)viewDidLoad { // Other initialisation… mapView.showsUserLocation = YES; }
    30. 30. Showing the User’s Location - (MKAnnotationView *)mapView:(MKMapView *)theMapView viewForAnnotation:(id <MKAnnotation>)annotation { // Checks to see if we are going to add the annotation for the users's location. // If this is the case, then we don't bother with creating an annotation and let // the platform give us the blue dot. if (annotation == mapView.userLocation) return nil; // Configuring other annotations… }
    31. 31. Resources WWDC 2009: Sessions 118 & 119 LocateMe Sample Application PragProg MapKit Screencast: http://pragprog.com/screencasts/v-bdmapkit
    1. A particular slide catching your eye?

      Clipping is a handy way to collect important slides you want to go back to later.

    ×