Place Annotations on Map with NSDictionary? - iphone

Thanks for the help in advance... this one has been killing me for the past couple of hours.
I am currently pulling in a JSON feed and storing it in a NSDictionary & NSArray. I'm trying to add an annotation for each item being pulled in (time, type, latitude, and longitude). So far, I can extract each value from the Array and have them all repeat with a "for" in the console (see code below).
How to I store these values as an annotation? Any help would be great.
Below is my failed attempt...
- (void)viewDidLoad {
[super viewDidLoad];
// Download JSON Feed
NSDictionary *feed = [self downloadFeed];
NSArray *streams = (NSArray *)[feed valueForKey:#"stream"];
[mapView setMapType:MKMapTypeStandard];
[mapView setZoomEnabled:YES];
[mapView setScrollEnabled:YES];
MKCoordinateRegion region = { {0.0, 0.0 }, { 0.0, 0.0 } };
region.center.latitude = 29.719023;
region.center.longitude = -114.157110;
region.span.longitudeDelta = 0.01f;
region.span.latitudeDelta = 0.01f;
[mapView setRegion:region animated:YES];
[mapView setDelegate:self];
int Info;
for (Info = 0; Info < streams.count; Info++) {
NSDictionary *stream = (NSDictionary *)[streams objectAtIndex:Info];
NSLog(#"Time: %#", [stream valueForKey:#"TheTime"]);
NSLog(#"Type: %#", [stream valueForKey:#"Type"]);
NSLog(#"Longitude: %#", [stream valueForKey:#"Longitude"]);
NSLog(#"Latitude: %#", [stream valueForKey:#"Latitude"]);
NSString *getLat = [[NSString alloc] initWithFormat: #"%#", [stream valueForKey:#"Latitude"]];
NSString *getLong = [[NSString alloc] initWithFormat: #"%#", [stream valueForKey:#"Longitude"]];
NSString *getCoord = [[NSString alloc] initWithFormat: #"{%#,%#}", getLat, getLong];
getCoordinates = getCoord;
DisplayMap *ann = [[DisplayMap alloc] init];
ann.title = #"%#", [stream valueForKey:#"TheTime"];
ann.subtitle = #"%#", [stream valueForKey:#"Type"];
ann.coordinate = getCoordinates;
[mapView addAnnotation:ann];
}
}
Here is the code for DisplayMap
DisplayMap.h
#import <Foundation/Foundation.h>
#import <MapKit/MKAnnotation.h>
#interface DisplayMap : NSObject <MKAnnotation> {
CLLocationCoordinate2D coordinate;
NSString *title;
NSString *subtitle;
}
#property (nonatomic, copy) NSString *title;
#property (nonatomic, copy) NSString *subtitle;
#property (nonatomic, readonly) CLLocationCoordinate2D coordinate;
#end
And now DisplayMap.m
#import "DisplayMap.h"
#implementation DisplayMap
#synthesize coordinate;
#synthesize title;
#synthesize subtitle;
-(void)dealloc{
[title release];
[super dealloc];
}
#end

What type is getCoordinates? Whatever the case, its definitely not being initialized right.
Assuming that your storing Latitude and Longitude as strings in your dictionary, this should do the trick.
double lat = [[stream valueForKey:#"Latitude"] doubleValue];
double lon = [[stream valueForKey:#"Longitude"] doubleValue];
CLLocationCoordinate2D coord = { lat, lon };
DisplayMap *ann = [[DisplayMap alloc] init];
ann.title = [stream valueForKey:#"TheTime"];
ann.subtitle = [stream valueForKey:#"Type"];
ann.coordinate = coord;
[mapView addAnnotation:ann];

At first glance :
ann.title = #"%#", [stream valueForKey:#"TheTime"];
should be
ann.title = [NSString stringWithFormat: #"%#", [stream valueForKey:#"TheTime"]];
I guess

Related

Only one Annotation showing

Hi my array is filled with three objects and only 1 annotation is showing on the map. Any ideas? If i NSLog certain elements it is filled. Just cant get the 3 annotations to show.
NSMutableArray *currentBranch = [xmlParser branch];
int counter=[currentBranch count];
NSMutableArray *new = [[NSMutableArray alloc] init];
CLLocationCoordinate2D coordinates;
Mapdets * myAnn;
myAnn = [[Mapdets alloc] init];
[mapview setMapType:MKMapTypeStandard];
[mapview setZoomEnabled:YES];
[mapview setScrollEnabled:YES];
MKCoordinateRegion region = {{0.0, 0.0}, {0.0,0.0 }};
region.center.latitude = -33.86434888;
region.center.longitude = 151.2090236;
region.span.longitudeDelta = 55.80f;
region.span.latitudeDelta = 55.80f;
[mapview setRegion:region animated:YES];
for(int i=0;i<counter;i++)
{
Mapdets *currentBranch = [[xmlParser branch] objectAtIndex:i];
NSString *title = currentBranch.title;
NSString *subtitle = currentBranch.subtitle;
NSString *lat = currentBranch.lat;
NSString *lng = currentBranch.lng;
coordinates.latitude = [lat doubleValue];
coordinates.longitude = [lng doubleValue];
myAnn.coordinate = coordinates;
myAnn.title = title;
myAnn.subtitle = subtitle;
NSLog(#"%#", title);
[new addObject:myAnn];
}
[mapview addAnnotations:new];
Thanks for the help!
Just initialise myAnn in for loop..
for(int i=0;i<counter;i++)
{
Mapdets * myAnn;
myAnn = [[Mapdets alloc] init];
Mapdets *currentBranch = [[xmlParser branch] objectAtIndex:i];
NSString *title = currentBranch.title;
NSString *subtitle = currentBranch.subtitle;
NSString *lat = currentBranch.lat;
NSString *lng = currentBranch.lng;
coordinates.latitude = [lat doubleValue];
coordinates.longitude = [lng doubleValue];
myAnn.coordinate = coordinates;
myAnn.title = title;
myAnn.subtitle = subtitle;
NSLog(#"%#", title);
[new addObject:myAnn];
}

Tracking user location all the time algorithm for an iphone app

I'm developing an iphone app that tracks the user location all the time.
The location can be in accuracy of handerts of meters (up to 400-500). And should be updated at least once an hour (even if there is no change in user's location, I would like to keep track on it)
I would like to know what is the best way to do that.
If I use CLLocation, I would like to use startupdatinglocation once in an hour and then use startmonitoringsignificantlocationchanges. Do you think it's the best way to do that causing minimum battery drain
The other option is using a geolocation api like geoloqi but i assume that using the realtime tracking mode all the time would cause a battery drain and the passive mode is not good enough accuracy (as i understood it gives accuracy like in wich city are you)
I would be glad if someone has any idea for a recommended api i could use or an efficient algorithm to use CLLocation to solve my problem.
Thank you!
You can track the location by maintaining a variable which reads the location from the GPS software and write the algorithm using a timer that reads the location every second or whatever precision u want
Try this code I think This will be work for you.
In .h file add this code
#import "CoreLocation/CoreLocation.h"
#import "MapKit/MapKit.h"
#interface AddressAnnotation : NSObject<MKAnnotation>
{
CLLocationCoordinate2D coordinate;
NSString *mTitle;
NSString *mSubTitle;
}
#end
#interface NearestPropertyMatchViewController : UIViewController<MKMapViewDelegate> {
CLLocationManager *locationManager;
IBOutlet MKMapView *searchMap;
NSMutableArray *searchListArray;
AddressAnnotation *addAnnotation;
}
-(CLLocationCoordinate2D) addressLocation:(NSString *)str;
#property (nonatomic, retain) CLLocationManager *locationManager;
#end
In .m file add this code.
- (void)viewDidLoad
{
[super viewDidLoad];
locationManager = [[CLLocationManager alloc] init];
locationManager.delegate = self;
locationManager.desiredAccuracy = kCLLocationAccuracyBest;
locationManager.distanceFilter = kCLDistanceFilterNone;
[locationManager startUpdatingLocation];
CLLocation *location = [locationManager location];
CLLocationCoordinate2D coordinate = [location coordinate];
NSString *latitude = [NSString stringWithFormat:#"%f", coordinate.latitude];
NSString *longitude = [NSString stringWithFormat:#"%f", coordinate.longitude];
NSLog(#"dLatitude : %#", latitude);
NSLog(#"dLongitude : %#",longitude);
MKCoordinateRegion region;
MKCoordinateSpan span;
span.latitudeDelta=100;
span.longitudeDelta=100;
region.span=span;
for(int i=0;i<[regestrationArray count];i++)
{
CLLocationCoordinate2D location = [self addressLocation:[regestrationArray objectAtIndex:i]];
region.center=location;
addAnnotation = [[AddressAnnotation alloc] initWithCoordinate:location];
[searchMap addAnnotation:addAnnotation];
[searchMap setRegion:region animated:TRUE];
[searchMap regionThatFits:region];
}
-(CLLocationCoordinate2D) addressLocation :(NSString *)str
{
NSError* error = nil;
NSString *urlString = [NSString stringWithFormat:#"http://maps.google.com/maps/geo?q=%#&output=csv",
[str stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];
NSString *locationString = [NSString stringWithContentsOfURL:[NSURL URLWithString:urlString] encoding:NSASCIIStringEncoding error:&error];
NSArray *listItems = [locationString componentsSeparatedByString:#","];
double latitude = 0.0;
double longitude = 0.0;
if([listItems count] >= 4 && [[listItems objectAtIndex:0] isEqualToString:#"200"]) {
latitude = [[listItems objectAtIndex:2] doubleValue];
longitude = [[listItems objectAtIndex:3] doubleValue];
}
else {
//Show error
}
CLLocationCoordinate2D location;
location.latitude = latitude;
location.longitude = longitude;
NSLog(#" lati=%f lon=%f",latitude,longitude);
return location;
}
- (MKAnnotationView *) mapView:(MKMapView *)mapView viewForAnnotation:(id <MKAnnotation>) annotation
{
MKPinAnnotationView *annView=[[MKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:#"currentloc"];
annView.pinColor = MKPinAnnotationColorGreen;
annView.animatesDrop=TRUE;
annView.canShowCallout = YES;
annView.calloutOffset = CGPointMake(-5, 5);
return annView;
}

Customize map annotations from plist

I found a short guide on how to load "annotation data" from a plist and add those annotations (pins) to a MapView.
My question is if anyone can tell me how I would customize the pins the most easily? As an example, I would like to define a color and an image in the plist and then have it set when adding the pins.
The pins are added like this:
MyAnnotation.m:
#implementation MyAnnotation
#synthesize title, subtitle, coordinate;
-(void) dealloc {
[super dealloc];
self.title = nil;
self.subtitle = nil;
}
MyAnnotation.h
#import <Foundation/Foundation.h>
#import <MapKit/MapKit.h>
#interface MyAnnotation : NSObject<MKAnnotation> {
CLLocationCoordinate2D coordinate;
NSString *title;
NSString *subtitle;
}
#property (nonatomic, assign) CLLocationCoordinate2D coordinate;
#property (nonatomic, copy) NSString* title;
#property (nonatomic, copy) NSString* subtitle;
Running through the plist in ViewDidLoad in MapViewController.m (array containg dictionaries for each pin) and adding annotations.
NSString *path = [[NSBundle mainBundle] pathForResource:#"Annotations" ofType:#"plist"];
NSMutableArray* anns = [[NSMutableArray alloc] initWithContentsOfFile:path];
for(int i = 0; i < [anns count]; i++) {
float realLatitude = [[[anns objectAtIndex:i] objectForKey:#"latitude"] floatValue];
float realLongitude = [[[anns objectAtIndex:i] objectForKey:#"longitude"] floatValue];
MyAnnotation* myAnnotation = [[MyAnnotation alloc] init];
CLLocationCoordinate2D theCoordinate;
theCoordinate.latitude = realLatitude;
theCoordinate.longitude = realLongitude;
myAnnotation.coordinate = theCoordinate;
myAnnotation.title = [[anns objectAtIndex:i] objectForKey:#"title"];
myAnnotation.subtitle = [[anns objectAtIndex:i] objectForKey:#"subtitle"];
[mapView addAnnotation:myAnnotation];
[annotations addObject:myAnnotation];
[myAnnotation release];
}
EDIT:
I have added the viewForAnnotation method which sets the color but how can I set the color of each pin individually?
-(MKAnnotationView *)mapView:(MKMapView *)mV viewForAnnotation:(id <MKAnnotation>)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 = MKPinAnnotationColorPurple;
pinView.canShowCallout = YES;
pinView.animatesDrop = YES;
}
else {
[mapView.userLocation setTitle:#"I am here"];
}
return pinView;
}
Solved! It can be done like this in the viewForAnnotation method:
for(MyAnnotation* a in mapView.annotations) {
if(annotation == a && annotation != mapView.userLocation) {
pinView.image = [UIImage imageNamed:a.annImage];
}
}

Reload JSON Feed within a UIView

I have a mapView that has annotation added through JSON (feed is stored in NSDictionary). Everything works great, but I want to add a feature.
I want the mapView to reload all of the annotations each time the view reappears (every time the tab bar is pressed). T've tried putting the part where the JSON is added to the NSDictionary in viewWillAppear {} .... but it does not work.
My code is below. Thanks in advance!
#import "MapViewController.h"
#import "DisplayMap.h"
#import "JSON/JSON.h"
#implementation MapViewController
#synthesize mapView;
#synthesize selectedType;
#synthesize locationManager;
// JSON from Server Actions
- (NSString *)stringWithUrl:(NSURL *)url {
NSURLRequest *urlRequest = [NSURLRequest requestWithURL:url
cachePolicy:NSURLRequestReturnCacheDataElseLoad
timeoutInterval:30];
// Fetch the JSON response
NSData *urlData;
NSURLResponse *response;
NSError *error;
// Make synchronous request
urlData = [NSURLConnection sendSynchronousRequest:urlRequest
returningResponse:&response
error:&error];
// Construct a String around the Data from the response
return [[NSString alloc] initWithData:urlData encoding:NSUTF8StringEncoding];
}
- (id)objectWithUrl:(NSURL *)url {
SBJsonParser *jsonParser = [SBJsonParser new];
NSString *jsonString = [self stringWithUrl:url];
// Parse the JSON into an Object
return [jsonParser objectWithString:jsonString error:NULL];
}
- (NSDictionary *) downloadFeed {
id response = [self objectWithUrl:[NSURL URLWithString:#"http://www.example.com/JSON"]];
NSDictionary *feed = (NSDictionary *)response;
return feed;
}
// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
- (void)viewDidLoad {
[super viewDidLoad];
locationManager = [[CLLocationManager alloc] init];
[locationManager setDelegate:self];
[locationManager setDesiredAccuracy:kCLLocationAccuracyBest];
[locationManager startUpdatingLocation];
mapView.mapType = MKMapTypeStandard;
mapView.zoomEnabled = YES;
mapView.scrollEnabled = YES;
mapView.showsUserLocation = YES;
MKCoordinateRegion region = { {0.0, 0.0 }, { 0.0, 0.0 } };
region.span.longitudeDelta = 0.005;
region.span.latitudeDelta = 0.005;
[mapView setRegion:region animated:YES];
[mapView setDelegate:self];
// Download JSON Feed
NSDictionary *feed = [self downloadFeed];
NSArray *streams = (NSArray *)[feed valueForKey:#"stream"];
int Info;
for (Info = 0; Info < streams.count; Info++) {
NSDictionary *stream = (NSDictionary *)[streams objectAtIndex:Info];
NSLog(#"Time: %#", [stream valueForKey:#"Time"]);
NSLog(#"Type: %#", [stream valueForKey:#"Type"]);
NSLog(#"Longitude: %#", [stream valueForKey:#"Longitude"]);
NSLog(#"Latitude: %#", [stream valueForKey:#"Latitude"]);
double lat = [[stream valueForKey:#"Latitude"] doubleValue];
double lon = [[stream valueForKey:#"Longitude"] doubleValue];
NSString *ttype = [[NSString alloc] initWithFormat: #"%#", [stream valueForKey:#"Type"]];
selectedType = ttype;
CLLocationCoordinate2D coord = {lat, lon};
DisplayMap *ann = [[DisplayMap alloc] init];
ann.title = [NSString stringWithFormat: #"%#", [stream valueForKey:#"Type"]];
ann.subtitle = [NSString stringWithFormat: #"%#", [stream valueForKey:#"Time"]];
ann.coordinate = coord;
[mapView addAnnotation:ann];
}
}
}
}
-(void)viewWillAppear { }
- (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation {
CLLocationCoordinate2D loc = [newLocation coordinate];
[mapView setCenterCoordinate:loc];
}
-(IBAction)refreshMap:(id)sender {
// Download JSON Feed
NSDictionary *feed = [self downloadFeed];
NSArray *streams = (NSArray *)[feed valueForKey:#"stream"];
int Info;
for (Info = 0; Info < streams.count; Info++) {
NSDictionary *stream = (NSDictionary *)[streams objectAtIndex:Info];
NSLog(#"Time: %#", [stream valueForKey:#"Time"]);
NSLog(#"Type: %#", [stream valueForKey:#"Type"]);
NSLog(#"Longitude: %#", [stream valueForKey:#"Longitude"]);
NSLog(#"Latitude: %#", [stream valueForKey:#"Latitude"]);
double lat = [[stream valueForKey:#"Latitude"] doubleValue];
double lon = [[stream valueForKey:#"Longitude"] doubleValue];
NSString *ttype = [[NSString alloc] initWithFormat: #"%#", [stream valueForKey:#"Type"]];
selectedType = ttype;
CLLocationCoordinate2D coord = {lat, lon};
DisplayMap *ann = [[DisplayMap alloc] init];
ann.title = [NSString stringWithFormat: #"%#", [stream valueForKey:#"Type"]];
ann.subtitle = [NSString stringWithFormat: #"%#", [stream valueForKey:#"Time"]];
ann.coordinate = coord;
[mapView addAnnotation:ann];
}
}
-(MKAnnotationView *)mapView:(MKMapView *)map viewForAnnotation:(id <MKAnnotation>)annotation {
if ([annotation isKindOfClass:[MKUserLocation class]])
return nil; //return nil to use default blue dot view
static NSString *AnnotationViewID = #"annotationViewID";
MKAnnotationView *annotationView = (MKAnnotationView *)[mapView dequeueReusableAnnotationViewWithIdentifier:AnnotationViewID];
if (annotationView == nil) {
annotationView = [[[MKAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:AnnotationViewID] autorelease];
}
annotationView.canShowCallout = YES;
if ([annotationView.annotation.title isEqualToString:#"Selected"]) {
UIImage *pinImage = [UIImage imageNamed:#"icon_selected.png"];
[annotationView setImage:pinImage];
}
annotationView.annotation = annotation;
return annotationView;
}
- (void)dealloc {
[mapView release];
self.adView.delegate = nil;
self.adView = nil;
[super dealloc];
}
#end
From UIViewController.h:
- (void)viewWillAppear:(BOOL)animated;
viewWillAppear is not the same as viewWillAppear:. Perhaps if you override the proper method it might work?
I think more details are needed. If viewWillAppear is not getting called then it is probably something to do with the way you are setting up the views.
These two links should give you some pointers.
How do I have a view controller run updating code when it is brought to the top of the stack of views?
and
What's the proper way to add a view controller to the view hierarchy?

iPhone MapView interrupted

I have a mapkit / view and it works fine - but I scroll around and after 2 - 10 moves my app crashed... and this only with a "interrupted".
Here is part of my code. I think it's a problem with the background threads and an array release / override problem.
Some background info: I generate a "session" key (MapKey) on mapview startup and save on the serverside a pin. The XML includes only new pins for a faster response and shorter XML.
// Update map when the user interacts with it
- (void)mapView:(MKMapView *)aMapView regionDidChangeAnimated:(BOOL)animated
{
MyAnnotation *annotation = [[MyAnnotation alloc] init];
MyAnnotation *ann = [[MyAnnotation alloc] init];
NSUserDefaults *prefs = [NSUserDefaults standardUserDefaults];
[UIApplication sharedApplication].networkActivityIndicatorVisible = YES;
NSString *postBody = [[[NSString alloc] initWithFormat:#"single=0&lat=%f&lng=%f&sid=%#", mapView.centerCoordinate.latitude, mapView.centerCoordinate.longitude, [prefs stringForKey:#"MapKey"], [prefs stringForKey:#"MapKey"]] autorelease];
[self performSelectorInBackground:#selector(getMark:) withObject:postBody];
}
// make post and interact with verarbeiten
-(void) getMark:(NSString *)postBody
{
NSAutoreleasePool *ccpool = [[NSAutoreleasePool alloc] init];
NSString *urlStr = [[[NSString alloc] initWithFormat:#"http://URL/get.php"] autorelease];
NSMutableURLRequest *request;
NSData *postData = [postBody dataUsingEncoding:NSUTF8StringEncoding];
NSError *error;
NSURLResponse *response;
NSData *dataReply;
id stringReply;
request = [NSMutableURLRequest requestWithURL: [NSURL URLWithString:urlStr]];
[request setHTTPMethod: #"POST"];
[request setHTTPBody:postData];
[request setValue:#"text/xml" forHTTPHeaderField:#"Accept"];
dataReply = [NSURLConnection sendSynchronousRequest:request returningResponse:&response error:&error];
stringReply = (NSString *)[[[NSString alloc] initWithData:dataReply encoding:NSUTF8StringEncoding] autorelease];
[self performSelectorInBackground:#selector(verarbeiten:) withObject:stringReply];
[ccpool release];
}
//generate annotations array with annotations an set it to mapview
-(void) verarbeiten:(NSString *)stringReply
{
NSAutoreleasePool *bbpool = [[NSAutoreleasePool alloc] init];
CXMLDocument *rssParser = [[[CXMLDocument alloc] initWithXMLString:stringReply options:0 error:nil] autorelease];
NSMutableArray* annotations = [[NSMutableArray alloc] init];
NSArray *resultNodes = nil;
resultNodes = nil;
resultNodes = [rssParser nodesForXPath:#"//place" error:nil];
for (CXMLElement *resultElement in resultNodes)
{
MyAnnotation *ann = [[MyAnnotation alloc] init];
ann.title = [[resultElement childAtIndex:3] stringValue];
ann.subtitle = [[resultElement childAtIndex:5] stringValue];
ann.currentPoint = [NSNumber numberWithInt:[[[resultElement childAtIndex:1] stringValue] intValue]];
MKCoordinateRegion region = { {0.0, 0.0 }, { 0.0, 0.0 } };
region.center.latitude = [[[resultElement childAtIndex:9] stringValue] floatValue];
region.center.longitude = [[[resultElement childAtIndex:7] stringValue] floatValue];
ann.coordinate = region.center;
//[mapView addAnnotation:ann ];
[annotations addObject:ann];
}
[mapView addAnnotations:annotations ];
[annotations release];
[UIApplication sharedApplication].networkActivityIndicatorVisible = NO;
[bbpool release];
}
- (MKAnnotationView *) mapView:(MKMapView *)mV viewForAnnotation:(MyAnnotation *) annotation
{
MKPinAnnotationView *pinView = nil;
if(annotation != mapView.userLocation)
{
static NSString *defaultPinID = #"de.my.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 = NO;
pinView.userInteractionEnabled = YES;
UIButton *btnVenue = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];
btnVenue.tag = [annotation.currentPoint intValue];
[btnVenue addTarget:self action:#selector(showLinks:) forControlEvents:UIControlEventTouchUpInside];
pinView.rightCalloutAccessoryView = btnVenue;
}
else
{
[mapView.userLocation setTitle:#"You are here"];
}
return pinView;
}
#import "MyAnnotation.h"
#implementation MyAnnotation
#synthesize coordinate, title, subtitle,currentPoint;
-(void)dealloc
{
[title release];
[subtitle release];
[super dealloc];
}
#end
#import <Foundation/Foundation.h>
#import <MapKit/MKAnnotation.h>
#interface MyAnnotation : NSObject <MKAnnotation>
{
CLLocationCoordinate2D coordinate;
NSString *title;
NSString *subtitle;
NSNumber *currentPoint;
}
#property (nonatomic, assign) CLLocationCoordinate2D coordinate;
#property (nonatomic, copy) NSString *title;
#property (nonatomic, copy) NSString *subtitle;
#property(nonatomic, retain) NSNumber *currentPoint;
#end
Just a thought: since -[MKMapView addAnnotations:] (potentially) performs UI modifications, you may want to call it in the main thread:
[mapView performSelectorOnMainThread: #selector(addAnnotations:) withObject: annotations waitUntilDone: YES];