In my app I have a map view which I want to have a pin drop and have an annotation call out of a title and subtitle. Here is what I have so far.
// Location Five.h
#import
#import
#import
#import
#import
#import
@interface Location_Five : UIViewController {
CLLocationCoordinate2D coordinate;
NSString *title;
NSString *subtitle;
NSString *latitude;
NSString *longitude;
NSArray *tableDataOne;
MKMapView *mapView;
}
@property (nonatomic, assign) CLLocationCoordinate2D coordinate;
@property (nonatomic, copy) NSString *title;
@property (nonatomic, copy) NSString *subtitle;
@property (nonatomic) BOOL animatesDrop;
@property (nonatomic, retain) IBOutlet MKMapView *mapView;
@property (nonatomic, retain) NSArray *tableDataOne;
@property (nonatomic, retain) NSString *latitude;
@property (nonatomic, retain) NSString *longitude;
@end// Location Five.m
// TableViewPush
//
// Created by Gary Benna on 6/3/11.
// Copyright 2011 BennArts. All rights reserved.
//
#import "Location Five.h"
#import "TableViewPushAppDelegate.h"
#import
#import
#import
#import "Area Two.h"
#import
@implementation Location_Five
-(id) init{
if((self = [super initWithNibName:@"Location Five" bundle:nil])){
}
return self;
}
@synthesize tableDataOne;
@synthesize mapView;
@synthesize coordinate,title,subtitle, animatesDrop, latitude, longitude;
- (void)viewDidLoad {
NSLog(@"InView did load");
[super viewDidLoad];
NSString *path = [[NSBundle mainBundle] pathForResource:@"tableDataOne" ofType:@"plist"];
self. tableDataOne = [NSArray arrayWithContentsOfFile:path];
for(int i = 0; i < [tableDataOne count]; i++) {
float realLatitude = [[[tableDataOne objectAtIndex:i] objectForKey:@"latitude"] floatValue];
float realLongitude = [[[tableDataOne objectAtIndex:i] objectForKey:@"longitude"] floatValue];
[mapView setMapType:MKMapTypeHybrid];
[mapView setZoomEnabled:YES];
[mapView setScrollEnabled:YES];
MKCoordinateRegion region = { {0.0,0.0}, {0.0,0.0} };
region.center.latitude = realLatitude;
region.center.longitude =realLongitude;
region.span.longitudeDelta = 0.10f;
region.span.latitudeDelta = 0.10f;
[mapView setRegion:region animated:YES];
[mapView setDelegate:self];
Location_Five *ann = [[Location_Five alloc] init];
ann.title =[[tableDataOne objectAtIndex:i] objectForKey:@"title"];
ann.subtitle = [[tableDataOne objectAtIndex:i] objectForKey:@"subtitle"];
ann.coordinate = region.center;
[mapView addAnnotation:ann];
}
}
-(MKAnnotationView *)mapView:(MKMapView *) mV viewForAnnotation:
(id )annotation {
MKPinAnnotationView *pinView = nil;
if(annotation !=mapView.userLocation)
{
static NSString *defaultPinID = @"com.invasivecode.pin";
pinView = (MKPinAnnotationView *) [mapView dequeueReusableAnnotationViewWithIdentifier:defaultPinID];
if (pinView == nil) pinView = [[[MKPinAnnotationView alloc]
initWithAnnotation:annotation reuseIdentifier:defaultPinID] autorelease];
pinView.pinColor = MKPinAnnotationColorRed;
pinView.canShowCallout = YES;
pinView.animatesDrop = YES;
}
else {
[mapView.userLocation setTitle:@"I am here"];
}
return pinView;
self.title = @"Pima Hall";
}
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "
http://www.apple.com/DTDs/PropertyList-1.0.dtd">
rows
text
Pima Hall
detailText
Three Entrances.
image
VisualGroupOne.THM.png
controller
Location_Five
title
Pima Hall
subtitle
East Entrance
latitude
32.045005
longitude
-110.782142
When I run the app and I open the viewController Location_Five a red pin drops I don't know where because there is no map view even tho I have placed into the IB and linked the map view to it. And there is no call out. Can anyone help me here. I think it is because maybe I am calling the wrong place in my plist.