I am very new to XCode and objective-c. This question may have been answered previously but I am somehow not able to make it work. My objective is to show multiple annotations on Google map. I have a bunch of Lats and Longs, however so far I have been able to show only one annotation. How can I show All the annotations at once. I have the code below for the MKMapView–
- (void)viewDidLoad {
// Set some coordinates for our position
CLLocationCoordinate2D location;
location.latitude = (double) 44.271745;
location.longitude = (double) -88.453265;
// Add the annotation to our map view
MapViewAnnotation *newAnnotation = [[MapViewAnnotation alloc] initWithTitle:@"Appleton" andCoordinate:location];
[self.mapview addAnnotation:newAnnotation];
[newAnnotation release];
self.mapview.region = MKCoordinateRegionMakeWithDistance(location,100000,100000);
}
I understand that I can loop through and instantiate newAnnotation and then use addAnnotation to add the annotation. But I am somehow not getting how to do it. This may be very basic, but I am very new to this. Any help will be appreciated.
//
// MapViewAnnotation.h
//
#import <Foundation/Foundation.h>
#import <MapKit/MapKit.h>
@interface MapViewAnnotation : NSObject <MKAnnotation> {
NSString *title;
CLLocationCoordinate2D coordinate;
}
@property (nonatomic, copy) NSString *title;
@property (nonatomic, readonly) CLLocationCoordinate2D coordinate;
- (id)initWithTitle:(NSString *)ttl andCoordinate:(CLLocationCoordinate2D)c2d;
@end
And
//
// MapViewAnnotation.m
//
#import "MapViewAnnotation.h"
@implementation MapViewAnnotation
@synthesize title, coordinate;
- (id)initWithTitle:(NSString *)ttl andCoordinate:(CLLocationCoordinate2D)c2d {
[super init];
title = ttl;
coordinate = c2d;
return self;
}
- (void)dealloc {
[title release];
[super dealloc];
}
@end
Looks like you only have one location. You should have list of latitude and longitude, then loop through that list and instantiate the MapViewAnnotation.