Introduction to MapKit

  • 29,959 views
Uploaded on

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

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

(From Melbourne Cocoaheads July 2009)

More in: Technology , Spiritual
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Be the first to comment
No Downloads

Views

Total Views
29,959
On Slideshare
0
From Embeds
0
Number of Embeds
13

Actions

Shares
Downloads
391
Comments
0
Likes
9

Embeds 0

No embeds

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
    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’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 & Managing Annotations
    Using Core Location to be able to plot the user’s current position on screen as well
    Other hints & 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’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 & Managing Annotations
    Using Core Location to be able to plot the user’s current position on screen as well
    Other hints & 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’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 & Managing Annotations
    Using Core Location to be able to plot the user’s current position on screen as well
    Other hints & 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’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 & Managing Annotations
    Using Core Location to be able to plot the user’s current position on screen as well
    Other hints & 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’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 & Managing Annotations
    Using Core Location to be able to plot the user’s current position on screen as well
    Other hints & 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’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 & Managing Annotations
    Using Core Location to be able to plot the user’s current position on screen as well
    Other hints & 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 & 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’s location on a map)
  • - Region takes an MKCoordinateRegion struct
    - Centre is the latitude & 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 & Subtitle are optional (although title is recommended).
    - T & ST are used as the primary & secondary labels on the default callout

Transcript

  • 1. An Intro to MapKit Rob Caporetto @rob_caporetto
  • 2. The Plan
  • 3. The Plan What is MapKit?
  • 4. The Plan What is MapKit? Adding MapKit to your iPhone Application
  • 5. The Plan What is MapKit? Adding MapKit to your iPhone Application Setting the Position
  • 6. The Plan What is MapKit? Adding MapKit to your iPhone Application Setting the Position Annotations
  • 7. The Plan What is MapKit? Adding MapKit to your iPhone Application Setting the Position Annotations Geocoding
  • 8. The Plan What is MapKit? Adding MapKit to your iPhone Application Setting the Position Annotations Geocoding Interacting with Core Location
  • 9. What is MapKit?
  • 10. Embed Maps in your App
  • 11. Adding MapKit to your App
  • 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. Setting the Position Set the region property Defines the center point and a span Span defines the vertical & horizontal distance to display
  • 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. Annotations
  • 16. Annotations Allow you to add places-of-interest to a Map Implemented with a Model & a View
  • 17. Annotation Models Implement the MKAnnotation protocol Exposes a Title, Subtitle, and Coordinate
  • 18. Title
  • 19. Title Subtitle
  • 20. Title Subtitle Coordinate
  • 21. Annotation Views Use MKAnnotationView Easiest trick to set the image property Use MKPinAnnotationView if you want the Pin
  • 22. Managing Annotation Views Managed like UITableViewCells
  • 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. Geocoding
  • 25. Geocoding Convert Landmarks into Longitude/Latitude and vice-versa SDK 3.0 Supports Reverse Geocoding only
  • 26. Reverse Geocoding Use MKReverseGeocoder Requires network access (Wifi/3G/EDGE) Asynchronous lookups
  • 27. Interacting with Core Location
  • 28. Showing the User’s Location Set the showsUserLocation property on the MapView instance Implement an Annotation
  • 29. Showing the User’s Location - (void)viewDidLoad { // Other initialisation… mapView.showsUserLocation = YES; }
  • 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. Resources WWDC 2009: Sessions 118 & 119 LocateMe Sample Application PragProg MapKit Screencast: http://pragprog.com/screencasts/v-bdmapkit