Your SlideShare is downloading. ×
Getting Oriented with
       MapKit
          Julio Barros
     Julio@E-String.com
Why Maps?

• iPhone is a mobile / pocket computer
• Where am I?
• How do I get somewhere?
• What’s near me?

             ...
Dark ages (pre 3.0)
• Static map images
• Web view with Javascript shenanigans
• Exit out to google maps


               ...
MapKit
• New in iPhone 3.x
• Embed map in your app
• Uses Google map tiles
• Familiar map UI

              Julio Barros E...
Important Classes
MKMapView


MKAnnotation (protocol)


MKAnnotationView

              Julio Barros E-String.com
Important Classes
MKMapView
   MKMapViewDelegate
MKAnnotation (protocol)


MKAnnotationView
   MKPinAnnotationView
       ...
Simplest Example

• MKMapView ... just a view


• Or use Interface Builder
• Don’t forget to add mapkit framework
        ...
That was
  easy




       Julio Barros E-String.com
Show User
 Location




      Julio Barros E-String.com
Showing a
particular area on
     the map
               Latitude Span
     Center



“best fit” not exactly
    what you s...
Regions
• MKCoordinateRegion




              Julio Barros E-String.com
Denver,
Colorado




      Julio Barros E-String.com
Demo data
plist of Brewery information: name, address,
latitude, longitude




               Julio Barros E-String.com
Loading Demo Data




      Julio Barros E-String.com
Local area




        Julio Barros E-String.com
MKAnnotation




   Julio Barros E-String.com
MyAnnotation Class




      Julio Barros E-String.com
Adding Annotations




      Julio Barros E-String.com
Default Pins at
 annotations




          Julio Barros E-String.com
Customizing pins
• MKPinAnnotationView
• MKMapViewDelegate - set a delegate




               Julio Barros E-String.com
Our purple
  pins




        Julio Barros E-String.com
Custom markers
• MKAnnotationView




             Julio Barros E-String.com
Customizing
 the view



        Julio Barros E-String.com
Customizing the
    Callout




    Julio Barros E-String.com
Tapping the call out
       view




       Julio Barros E-String.com
Reverse Geocoding

• Geocoding : address to coordinates
 • geocoder.us other services
• Reverse geocoding : coordinates to...
MKReverseGeocoder




      Julio Barros E-String.com
MKPlacemark
• Address info including, country code,
  country, postal code, administrative area,
  sub administrative area...
Number of pins
• Try to limit
  annotations to ~100(?)
• Implement region
  change delegate
  methods
• Create and manage
...
Challenges
• Anchoring an object to a location on the
  map and having it scale.
• Shapes - neighborhoods
• Lines - routes...
Legal limitations
I’m not a lawyer but think carefully before using this
for:
   vehicle/fleet tracking
   routing
   cache...
Possible Options

• OpenStreetMap.org (OSM) - map/tile data
• Route-Me - OSS map view
• Cloudemade.com - services around O...
Resources

• MapKit Framework Reference - Apple
• Using Map Kit with Bill Dudney - PragProg
• Using Map Kit ... Bill Dudne...
Thank You
Julio Barros
Julio@E-String.com
http://www.E-String.com
http://twitter.com/JulioBarros
Also on Face book and Lin...
Upcoming SlideShare
Loading in...5
×

Getting Oriented with MapKit

5,408

Published on

Slides of a presentation I did at 360iDev in Denver in September 2009. Sample code is available at E-String.com
Let me know if you have any questions.

Transcript of "Getting Oriented with MapKit"

  1. 1. Getting Oriented with MapKit Julio Barros Julio@E-String.com
  2. 2. Why Maps? • iPhone is a mobile / pocket computer • Where am I? • How do I get somewhere? • What’s near me? Julio Barros E-String.com
  3. 3. Dark ages (pre 3.0) • Static map images • Web view with Javascript shenanigans • Exit out to google maps Julio Barros E-String.com
  4. 4. MapKit • New in iPhone 3.x • Embed map in your app • Uses Google map tiles • Familiar map UI Julio Barros E-String.com
  5. 5. Important Classes MKMapView MKAnnotation (protocol) MKAnnotationView Julio Barros E-String.com
  6. 6. Important Classes MKMapView MKMapViewDelegate MKAnnotation (protocol) MKAnnotationView MKPinAnnotationView Julio Barros E-String.com
  7. 7. Simplest Example • MKMapView ... just a view • Or use Interface Builder • Don’t forget to add mapkit framework Julio Barros E-String.com
  8. 8. That was easy Julio Barros E-String.com
  9. 9. Show User Location Julio Barros E-String.com
  10. 10. Showing a particular area on the map Latitude Span Center “best fit” not exactly what you set Longitude Span Julio Barros E-String.com
  11. 11. Regions • MKCoordinateRegion Julio Barros E-String.com
  12. 12. Denver, Colorado Julio Barros E-String.com
  13. 13. Demo data plist of Brewery information: name, address, latitude, longitude Julio Barros E-String.com
  14. 14. Loading Demo Data Julio Barros E-String.com
  15. 15. Local area Julio Barros E-String.com
  16. 16. MKAnnotation Julio Barros E-String.com
  17. 17. MyAnnotation Class Julio Barros E-String.com
  18. 18. Adding Annotations Julio Barros E-String.com
  19. 19. Default Pins at annotations Julio Barros E-String.com
  20. 20. Customizing pins • MKPinAnnotationView • MKMapViewDelegate - set a delegate Julio Barros E-String.com
  21. 21. Our purple pins Julio Barros E-String.com
  22. 22. Custom markers • MKAnnotationView Julio Barros E-String.com
  23. 23. Customizing the view Julio Barros E-String.com
  24. 24. Customizing the Callout Julio Barros E-String.com
  25. 25. Tapping the call out view Julio Barros E-String.com
  26. 26. Reverse Geocoding • Geocoding : address to coordinates • geocoder.us other services • Reverse geocoding : coordinates to address Julio Barros E-String.com
  27. 27. MKReverseGeocoder Julio Barros E-String.com
  28. 28. MKPlacemark • Address info including, country code, country, postal code, administrative area, sub administrative area, locality, sub locality, thoroughfare, sub thoroughfare • Conforms to MKAnnotation • Has address dictionary with Address Book keys Julio Barros E-String.com
  29. 29. Number of pins • Try to limit annotations to ~100(?) • Implement region change delegate methods • Create and manage your own clusters Julio Barros E-String.com
  30. 30. Challenges • Anchoring an object to a location on the map and having it scale. • Shapes - neighborhoods • Lines - routes / paths • View space to Geo Space - (CGPoint)convertCoordinate:(CLLocationCoordinate2D) coordinate toPointToView:(UIView *)view - (CLLocationCoordinate2D)convertPoint:(CGPoint)point toCoordinateFromView:(UIView *)view Julio Barros E-String.com
  31. 31. Legal limitations I’m not a lawyer but think carefully before using this for: vehicle/fleet tracking routing cacheing tiles geocoding / mass reverse geocoding Read the TOS http://code.google.com/apis/maps/iphone/ terms.html Julio Barros E-String.com
  32. 32. Possible Options • OpenStreetMap.org (OSM) - map/tile data • Route-Me - OSS map view • Cloudemade.com - services around OSM • geocoder.us (among others) Julio Barros E-String.com
  33. 33. Resources • MapKit Framework Reference - Apple • Using Map Kit with Bill Dudney - PragProg • Using Map Kit ... Bill Dudney - Wednesday Julio Barros E-String.com
  34. 34. Thank You Julio Barros Julio@E-String.com http://www.E-String.com http://twitter.com/JulioBarros Also on Face book and Linked In Julio Barros E-String.com

×