Reputation: 31
I have placed two pins on a map, each with an annotation when clicked, however, only the annotation for StoreLocationOne
is showing. Both pins on the map are being displayed but StoreLocationTwo
annotation is not showing when clicked, any ideas?
-(void)viewDidLoad {
[super viewDidLoad];
[mapview setMapType:MKMapTypeStandard];
[mapview setZoomEnabled:YES];
[mapview setScrollEnabled:YES];
MKCoordinateRegion region = { {0.0, 0.0 }, {0.0, 0.0 } };
region.center.latitude = 57.132053;
region.center.longitude = -2.135592;
region.span.longitudeDelta = 0.01f;
region.span.latitudeDelta = 0.01f;
[mapview setRegion:region animated:YES];
StoreLocationOne *ann = [[StoreLocationOne alloc] init];
ann.title = @"Heavenly Pizzas Mannofield";
ann.subtitle = @"483a Great Western Rd, Aberdeen, AB10 6NN";
ann.coordinate = region.center;
[mapview addAnnotation:ann];
MKCoordinateRegion region2 = { {0.0, 0.0 }, {0.0, 0.0 } };
region2.center.latitude = 57.232458;
region2.center.longitude = -2.347853;
region2.span.longitudeDelta = 0.01f;
region2.span.latitudeDelta = 0.01f;
StoreLocationTwo *ann2 = [[StoreLocationTwo alloc] init];
ann2.title2 = @"Heavenly Pizzas Kintore";
ann2.subtitle2 = @"School Road, Kintore, AB51 0UU";
ann2.coordinate = region2.center;
[mapview addAnnotation:ann2];
}
Upvotes: 1
Views: 1065
Reputation:
The title
and subtitle
properties must be named exactly that. The map view won't know to look for title2
and subtitle2
.
You can have multiple classes that implement MKAnnotation
but the property names must be as per the protocol.
Additionally, if all you need are the properties coordinate
, title
, and subtitle
, you could use the built-in annotation class MKPointAnnotation
instead of creating a separate class for each coordinate.
Upvotes: 1