Advertise here




Advertise here

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Sign In with Google Sign In with OpenID
Please do not post the same thing multiple times. The board software automatically flags certain posts as needing moderator attention. This happens the most often for new users. I'm pretty sure this is made clear at the time you attempt to post. Posting the same thing over and over again just makes that many more posts the moderators have to weed through later. This makes us sad. Don't make us sad. If your post/thread doesn't appear, just wait a while. Don't post it again. If it hasn't shown up by the next day, then you can try again. I normally go through posts in the mornings, and try to check a few times throughout the day, but I'm not here 24/7. There will typically be a significant delay before posts are approved. Just be patient.

populating a pin drop and call out from plist map view

gbennagbenna Posts: 99Registered Users
edited September 2011 in iPhone SDK Development
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.
Sign In or Register to comment.