Map kit

630 views

Published on

0 Comments
1 Like
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total views
630
On SlideShare
0
From Embeds
0
Number of Embeds
2
Actions
Shares
0
Downloads
13
Comments
0
Likes
1
Embeds 0
No embeds

No notes for slide

Map kit

  1. 1. Intro to the MapKit Code Review: 3/30/12
  2. 2. The Plan What is MapKit? Adding MapKit to your iPhone Application Setting the Position Annotations Geocoding Interacting with Core Location
  3. 3. What is MapKit? Embed Maps in your App Based on Google Maps
  4. 4. 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
  5. 5. Setting the Position Set the region property Define the center point and a span Span defines the vertical & horizontal distance to display (zoom) - (void)viewDidLoad
{
 MKCoordinateRegion region;
 region.center.latitude = [eventVenue.latitude doubleValue }
  6. 6. Annotations Allow you to add places-of-interest to a Map Implemented with a Model & a View Only limited by amount of free memory on the device
  7. 7. Annotation Models Implement the MKAnnotation protocol Exposes a Title, Subtitle, and Coordinate Title Subtitle Coordinate
  8. 8. Annotation Views Use MKAnnotationView Easiest trick to set the image property Use MKPinAnnotationView if you want the Pin If you don’t need a specific image, it’s best to just use the Pin. NB: Pin has 3 different colors: Red (which is the default for indicating a location), Green (for indicating the start point), and Purple (which is user defined).
  9. 9. 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;
}
  10. 10. Geocoding Convert Landmarks into Longitude/Latitude
and vice-versa SDK 3.0+ Supports Reverse Geocoding only For forward geocoding, you can use services like Google or Yahoo
  11. 11. Reverse Geocoding Use MKReverseGeocoder Requires network access (Wifi/3G/EDGE) Asynchronous lookups
  12. 12. Interacting with Core Location Set the showsUserLocation property on the MapView instance Implement an Annotation Setting showsUserLocation to YES enables it (so you’ll get CL authorization pop-ups) - (void)viewDidLoad
{ // Other initialisation… mapView.showsUserLocation = YES; }
  13. 13. Showing the User’s Location- (MKAnnotationView *)mapView:(MKMapView *)theMapView viewForAnnotation:(id <MKAnnotation>)annotation
{
 // Checks to see if weare going to add the annotation for the userss location.
 // If this is the case, then wedont bother with creating an annotation and let
 // the platform give us the bluedot.
 if (annotation == mapView.userLocation) return nil;
 // Configuring other annotations…
}

×