Advertise Mobile SDKs Books Events Forum News Social Networking Support Us
Follow @iphonedevsdk on Twitter

Interface 2, Advanced iOS
Mockup & Code Gen
($9.99)

Make your own iPhone apps
and run them live!
(free)

Pic Frame Dynamo: Photo Editing
($0.99)

Abiliator
($1.99)

Want your application or service advertised on iPhone Dev SDK?

Go Back   iPhone Dev SDK Forum > iPhone SDK Development Forums > iPhone SDK Development

Reply
 
LinkBack Thread Tools Display Modes
Old 09-09-2011, 11:35 PM   #1 (permalink)
Registered Member
 
Join Date: Jul 2011
Posts: 67
gbenna is on a distinguished road
Default populating a pin drop and call out from plist map view

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 <UIKit/UIKit.h>
#import <AVFoundation/AVFoundation.h>
#import <AudioToolbox/AudioToolbox.h>
#import <MapKit/MapKit.h>
#import <CoreLocation/CoreLocation.h>
#import <MapKit/MKAnnotationView.h>

@interface Location_Five : UIViewController <AVAudioPlayerDelegate, MKMapViewDelegate, MKAnnotation> {


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 <AVFoundation/AVAudioPlayer.h>
#import <MapKit/MapKit.h>
#import <CoreLocation/CoreLocation.h>
#import "Area Two.h"
#import <MapKit/MKAnnotationView.h>
@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 arrayWithContentsOfFileath];

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 *)mapViewMKMapView *) mV viewForAnnotation:
(id <MKAnnotation>)annotation {
MKPinAnnotationView *pinView = nil;
if(annotation !=mapView.userLocation)
{
static NSString *defaultPinID = @"com.invasivecode.pin";
pinView = (MKPinAnnotationView *) [mapView dequeueReusableAnnotationViewWithIdentifier:defaul tPinID];
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">
<plist version="1.0">
<array>
<dict>
<key>rows</key>
<array>
<dict>
<key>text</key>
<string>Pima Hall</string>
<key>detailText</key>
<string>Three Entrances.</string>
<key>image</key>
<string>VisualGroupOne.THM.png</string>
<key>controller</key>
<string>Location_Five</string>
<key>title</key>
<string>Pima Hall</string>
<key>subtitle</key>
<string>East Entrance</string>
<key>latitude</key>
<string>32.045005</string>
<key>longitude</key>
<string>-110.782142</string>
</dict>

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.
gbenna is offline   Reply With Quote
Reply

Bookmarks

Tags
annotation, callout, mapview, plist

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



» Advertisements
» Online Users: 412
9 members and 403 guests
apatsufas, Eclectic, fiftysixty, JackReidy, teebee74, tim0504, UMAD, yomo710, yuncarl28
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,672
Threads: 94,121
Posts: 402,904
Top Poster: BrianSlick (7,990)
Welcome to our newest member, yuncarl28
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 05:01 AM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0