Redrawing markers on a Route-me map - ios

Working in iOS 6, I cannot seem to get the map view to update itself to show markers added or removed.
When the app opens, a number of markers are placed on the map. The user can then make choices that add new markers and/or remove existing markers. This uses the same method as when the RMMarkerManager is populated at viewWillLoad, and I can iterate through the markers in the RMMarkerManager and see that it has the new set of markers, but the map view never updates to show them.
I have tried [mapview setNeedsDisplay] with no effect.
Clearly, I'm missing something that causes the mapview to update the display of the markers, but I have not figured out what, despite lots of head-scratching and digging through documentations and posts.
I will appreciate any suggestions as to what I should change or add.
As requested, here is the appropriate code. I'll explain how it works.
In the viewController's createMarkers method, the markers are created by accessing a sqlite database. One marker is created for each record that I want displayed as a marker on the map. I then iterate through the array of markers, adding each to the mapView's marketManager (addMarker method). The method createMarkers is called in the viewController's viewWillLoad method, and works correctly: all markers are displayed.
When using the app, a user can select or de-select records in the database. Then the viewController receives a notification that the user has changed the selection, and calls its setMarkers method. The mapview's marketmanager gets a removeMarkers message, then the marker array is re-created; it now has markers reflecting the user's selections. But the map never updates the on-view markers. Markers removed by the user are not removed on the view; markers added by the user are not added.
After the update, I can iterate through mapview.markermanager.markers and see that it now contains the new markers. But they're never shown on the mapView.
Class: Marker, subclass of RMMarker.
Simply holds data about the marker to be displayed
Marker.h:
// Marker.h
#import <Foundation/Foundation.h>
#import "Location.h"
#import "RMMarker.h"
#interface Marker : RMMarker {
NSString *category_name;
NSString *name;
NSString *desc;
NSString *address;
NSString *png;
int marker_id;
float lat;
float longi;
CLLocationCoordinate2D node;
float label_x_offset;
float label_y_offset;
}
#property (nonatomic, strong) NSString *category_name;
#property (nonatomic, retain) NSString *name;
#property (nonatomic, retain) NSString *desc;
#property (nonatomic, retain) NSString *address;
#property (nonatomic, retain) NSString *png;
#property (nonatomic) int marker_id;
#property (nonatomic) float lat;
#property (nonatomic) float longi;
#property (nonatomic) CLLocationCoordinate2D node;
#property (nonatomic) float label_x_offset;
#property (nonatomic) float label_y_offset;
#end
Class: Markers
Holds an NSMutableArray of Markers, which is populated from a sqlite database:
// Markers.m
#import "Markers.h"
#import "defs.h"
#import "FileLocator.h"
#import "Marker.h"
#implementation Markers
#synthesize markers;
-(NSMutableArray *) createMarkers {
markers = [[NSMutableArray alloc] init];
[self openDatabase];
NSString *query = [NSString stringWithFormat:#"SELECT categories.selected, categories.category_id, categories.png, places.name, address, description, latitude, longitude, place_id FROM places, categories WHERE (categories.selected = 1 AND places.category_id = categories.category_id);"];
debugPrintArgs(#"query: %#", query);
FMResultSet *rs = [db executeQuery:query];
while ([rs next]) {
Marker *marker = [[Marker alloc] init];
marker.marker_id = [rs intForColumn:#"place_id"];
marker.name = [rs stringForColumn:#"name"];
marker.address = [rs stringForColumn:#"address"];
marker.desc = [rs stringForColumn:#"description"];
marker.lat = [rs doubleForColumn:#"latitude"];
marker.longi = [rs doubleForColumn:#"longitude"];
marker.png = [rs stringForColumn:#"png"];
debugPrintArgs(#"%#, %#, %#, %f, %f", marker.name, marker.address, marker.description, marker.lat, marker.longi);
marker.label_y_offset = 150.0f;
marker.label_x_offset = 30.0f;
[markers addObject:marker];
}
[db close];
return markers;
}
#end
Methods in the viewcontroller:
setMarkers:
Iterates through the NSMUtableArray Markers, calling the method addMarker: for each marker in that array:
- (void) setMarkers {
// class Markers is essentially an NSMutableArray that holds instantiations of Marker - one for each marker to be displayed
// Markers is also responsible for populating itself from a sqlite database via the createMarkers method
Markers *markers = [[Markers alloc] init];
NSMutableArray *allMarkers = [markers createMarkers];
// allMarkers contains the markers to be displayed.
CLLocationCoordinate2D loc;
if ([allMarkers count] > 0) {
for (Marker *mrkr in allMarkers) {
loc.longitude = mrkr.longi;
loc.latitude = mrkr.lat ;
[self addMarker: mrkr at:loc withText:mrkr.name xOffset: mrkr.label_x_offset yOffset: mrkr.label_y_offset png: mrkr.png];
}
}
}
Also in the viewController: addMarker
And, finally, the addMarker method used to add a marker to the RMMarkerManager:
- (void) addMarker: (Marker *) marker at:(CLLocationCoordinate2D)loc withText:(NSString *)text xOffset: (float) x_offset yOffset:(float) y_offset png:(NSString *) png {
UIImage* markerImage = [UIImage imageNamed:png];
[marker replaceUIImage:markerImage anchorPoint:CGPointMake(0.38f, 1.08f)];
[viewMap.markerManager addMarker: marker AtLatLong: loc];
CGPoint position = CGPointMake( 0.0f, 0.0f);
[marker changeLabelUsingText: text position: position ];
}

The offending line here is in setMarkers:
Markers *markers = [[Markers alloc] init];
Making markers an instance variable and doing the alloc-init in the class's viewWillLoad method corrected the problem.
I wish I could explain this better, but I am unsure as to why this caused the problem. But, it's corrected now and I'll explore when I've got some time.

Related

The Pin is not working

My Map shows a pin on a specific place but it's not showing the pin
Here is the code
WadiRumViewControllerJordan.h
#import <UIKit/UIKit.h>
#include <MapKit/MapKit.h>
#interface WadiRumViewControllerJordan : UIViewController
#property (strong, nonatomic) IBOutlet MKMapView *WadiRumMapView;
#end
WadiRumViewControllerJordan.m
#import "WadiRumViewControllerJordan.h"
#import "WadiRumNSOjectPIN.h"
#interface WadiRumViewControllerJordan ()
#end
//Wadi Rum Coordinates
#define WadiRum_Latitude 29.537355
#define WidiRum_longtitude 35.415026
//Wadi Rum Span
#define WadiRumSpan 0.01f;
#implementation WadiRumViewControllerJordan
#synthesize WadiRumMapView;
- (void)viewDidLoad {
[super viewDidLoad];
//Create WadiRum Region
MKCoordinateRegion WadiRumRegion;
//Center
CLLocationCoordinate2D center;
center.latitude = WadiRum_Latitude;
center.longitude = WidiRum_longtitude;
//Span
MKCoordinateSpan span;
span.latitudeDelta = WadiRum_Latitude;
span.longitudeDelta = WidiRum_longtitude;
WadiRumRegion.center = center;
WadiRumRegion.span = span;
//Set our map
[WadiRumMapView setRegion:WadiRumRegion animated:YES];
//WadiRumNSObjectPIN
//1. Create a coordinate for the use of WadiRum
CLLocationCoordinate2D WadiRumLocation;
WadiRumLocation.latitude = WadiRum_Latitude;
WadiRumLocation.longitude = WidiRum_longtitude;
WadiRumNSOjectPIN * WadiRumAnnitation = [[WadiRumNSOjectPIN alloc] init];
WadiRumAnnitation.coordinate = WadiRumLocation;
WadiRumAnnitation.title = #"Services";
WadiRumAnnitation.subtitle = #"Desert";
{[self.WadiRumMapView addAnnotation:WadiRumAnnitation];
}
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be WadiRumNSOjectPIN
}
#end
WadiRumNSOjectPIN.h
#import <Foundation/Foundation.h>
#import <MapKit/MapKit.h>
#interface WadiRumNSOjectPIN : NSObject <MKAnnotation>
#property(nonatomic, assign) CLLocationCoordinate2D coordinate;
#property(nonatomic, copy) NSString * title;
#property(nonatomic, copy) NSString * subtitle;
#end
WadiRumNSOjectPIN.m
#import "WadiRumNSOjectPIN.h"
#implementation WadiRumNSOjectPIN
#synthesize coordinate;
- (id)initWithLocation:(CLLocationCoordinate2D)coord {
self = [super init];
if (self) {
coordinate = coord;
}
return self;
}
#synthesize coordinate, title, subtitle;
#end
I edited the code above to make it exactly like what I want, I got this error in the picture bellow
In order to conform to MKAnnotation, you must have properties called coordinate, title and subtitle. You've added three extra properties, ttcoordinate, tttitle, and ttsubtitle, but MKAnnotation is going to ignore those, and will look for coordinate, title, and subtitle.
The key reason you're not seeing your annotation is that you're setting ttcoordinate in viewDidLoad. But MKAnnotation will not use that, but rather will refer to the coordinate property you synthesized, but never set. (You do have an initWithLocation method, which suggests you were going to update coordinate, but you never call that.)
Bottom line, I would suggest renaming ttcoordinate, ttitle and ttsubtitle to coordinate, title, and subtitle, and updating all of those references accordingly, and that should fix everything. And you can retire the #synthesize line.

Get values from NSMutablearray

I have a NSMutableArray that has three columns with multiple lines with float values, like this:
-0.06, -0.49, -0.76;
-1.05, -0.63, -0.77;
0.73, -0.32, -0.62;
-0.08, -0.61, -1.00;
0.15, -0.42, -0.91;
I used this lines to define the NSMutableArray (anArrayAcel):
NSString *str = [NSString stringWithFormat:#"%#, %#, %#",self.accX.text,self.accY.text, self.accZ.text];
[anArrayAcel addObject:str];
I need access this data to be used in other function. How can I access the values through specific indexes?
It looks like you need an array of arrays. You made an array of NSStrings instead.
Here is one way to do it:
NSMutableArray *row = [
#[
[self.accX.text floatValue]
, [self.accY.text floatValue]
, [self.accZ.text floatValue]
]
mutableCopy
];
[anArrayAcel addObject:row];
The idea is to create an array of NSMutableArrays, presumably in an event handler inside which you add rows to your array. If you do not need the nested arrays to be mutable, skip the mutableCopy part.
Now you can access your data as follows:
float x = anArrayAcel[row][0];
float y = anArrayAcel[row][1];
float z = anArrayAcel[row][2];
Note: if all rows are going to have exactly three values, x, y, and z, you may be better off creating a class to represent three floats instead of using a nested array.
you can design a class named Acel as below:
// Acel.h
#import <Foundation/Foundation.h>
#import <UIKit/UIKit.h>
#interface Acel : NSObject
#property (nonatomic, assign) CGFloat accX;
#property (nonatomic, assign) CGFloat accY;
#property (nonatomic, assign) CGFloat accZ;
- (instancetype)initWithAccX:(CGFloat)accX accY:(CGFloat)accY accZ:(CGFloat)accZ;
#end
and .m is as below:
// Acel.m
#import "Acel.h"
#implementation Acel
- (instancetype)initWithAccX:(CGFloat)accX accY:(CGFloat)accY accZ:(CGFloat)accZ{
self = [super init];
if (self) {
self.accX = accX;
self.accY = accY;
self.accZ = accZ;
}
return self;
}
#end
ViewController as below:
// ViewController.h
#interface ViewController ()
#property (nonatomic, strong) NSMutableArray *acels;
#end
#implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
self.acels = [#[] mutableCopy];
Acel *acel0 = [[Acel alloc] initWithAccX:-1.1f accY:0.2f accZ:0.3f];
Acel *acel1 = [[Acel alloc] initWithAccX:-1.1444f accY:0.22f accZ:0.33f];
Acel *acel2 = [[Acel alloc] initWithAccX:-1.1411f accY:0.255f accZ:0.333f];
[_acels addObject:acel0];
[_acels addObject:acel1];
[_acels addObject:acel2];
[self accessAccel1X];
}
- (void)accessAccel1X{
Acel * acel1 = self.acels[1];
NSLog(#"%f", acel1.accX);
}
In my opinion,it is more elegant compared with two-dimensional array.
Because we don't need do like [0][1] and we avoid double circulation if you want to iterate through arrays,

Re-using this code for multiple mapkit pin annotations

I have this code below working perfectly for a unique Pin and one annotation. I want to adapt it without too many changes to display more Pins, locations and annotations.
There is a class called MyAnnotationPins with the following lines:
MyAnnotationPins.h
#interface MyAnnotationPins : NSObject < MKAnnotation>
#property (nonatomic, readonly) CLLocationCoordinate2D coordinate;
#property (nonatomic, readonly, copy) NSString *title;
#property (nonatomic, readonly, copy) NSString *subtitle;
-(id)initWithCoordinate:(CLLocationCoordinate2D)annotCoordinate title:(NSString*)annotTitle subtitle:(NSString*)annotSubtitle;
MyAnnotationPins.m
#synthesize coordinate;
#synthesize subtitle;
#synthesize title;
-(id)initWithCoordinate:(CLLocationCoordinate2D)annotCoordinate title:(NSString*)annotTitle subtitle:(NSString*)annotSubtitle
{
self = [super init];
if (self)
{
coordinate = annotCoordinate;
subtitle = [[NSString alloc] initWithString:annotSubtitle];
title = [[NSString alloc] initWithString:annotTitle];
}
return self;
}
And at the view controller the following code:
SecondViewController.h
import "MyAnnotationPins.h"
#interface SecondViewController : UIViewController < MKMapViewDelegate >
#property (weak, nonatomic) IBOutlet MKMapView *mapView;
#property (strong, nonatomic) MyAnnotationPins* biblioAnnotation;
At the SecondViewController.m the implementation:
- (void)viewDidLoad
{
[super viewDidLoad];
mapView.delegate = self;
MKCoordinateRegion mapRegion;
mapRegion.center.latitude=-18.924129;
mapRegion.center.longitude=-48.283963;
mapRegion.span.latitudeDelta=0.2;
mapRegion.span.longitudeDelta=0.2;
[mapView setRegion:mapRegion animated:YES];
///// This is just for One annotaion/Pin on Map /////
CLLocationCoordinate2D parliamentLocation = CLLocationCoordinate2DMake(-18.924129, -48.283963);
biblioAnnotation = [[MyAnnotationPins alloc]
initWithCoordinate:parliamentLocation
title:#"Ponto Biblioteca"
subtitle:#"Taxi proximo"];
[mapView addAnnotation:biblioAnnotation];
If you want more than one pin and annotaion copy the CLLocation instance below and change the following atributes
CLLocationCoordinate2D secondLocation = CLLocationCoordinate2DMake(another latitude, another longitude);
secondAnnotation = [[MyAnnotationPins alloc]
initWithCoordinate:secondLocation
title:#"Second Title"
subtitle:#"Second subtitle"];
[mapView addAnnotation:secondAnnotation]; <code>
And so on for the third, fourth fifth etc. Do not forget to create the secondLocation proerty at your view controller like the first one in SecondViewController.h and also
#synthesize secondAnnotation property at SecondViewController.m file
#property (strong, nonatomic) MyAnnotationPins* secondAnnotation;
Add them in a loop like so
for(X in Y)
{
CLLocationCoordinate2D parliamentLocation = CLLocationCoordinate2DMake(-18.924129, -48.283963);
MyAnnotationPins* biblioAnnotation = [[MyAnnotationPins alloc]
initWithCoordinate:parliamentLocation
title:#"Ponto Biblioteca"
subtitle:#"Taxi proximo"];
[mapView addAnnotation:biblioAnnotation];
}
As you loop through your list you can get the right coordinates and title for each one. This way you list can grow or shrink and you won't need to add third, fourth or fifth annotation properties.

IOS 4.3.2 MapKit Annotations

Hello we have an app that we are working on that is having some issuse getting the annotations to function correctly. The app builds and installs fine... there are about 50k pins being loaded from a database on the ipad...
The problem is that every pin will display the same annotation information when pressed... can't figure out how to have it reference the correct database field when a pin is pressed (the pins are all being displayed in the correct locations so we know it is referencing the database)
I imagine it's something here?
- (void) loadThePushPinInMap {
NSString * filename= [[NSBundle mainBundle] pathForResource:#"geocoded" ofType:#"csv"];
NSString *data = [NSString stringWithContentsOfFile:filename];
NSString *strippedPartOne = [data stringByReplacingOccurrencesOfString:#"\"" withString:#""];
NSArray *rows = [strippedPartOne componentsSeparatedByString:#"\r"];
int size = [rows count];
for (int i =0; i < size; i++) {
if(i==0)
continue;
// This is now the data being parse
NSArray * line = [[rows objectAtIndex:i] componentsSeparatedByString:#","];
double lat =[[[line objectAtIndex:5] stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]] doubleValue];
double lon =[[[line objectAtIndex:6] stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]] doubleValue];
//MKCoordinateRegion region = { {0.0, 0.0 }, { 0.0, 0.0 } };
//region.center.latitude = lat ;
//region.center.longitude = lon;
//region.span.longitudeDelta = 0.01f;
//region.span.latitudeDelta = 0.01f;
CLLocationCoordinate2D coordinate;
coordinate.latitude = lat;
coordinate.longitude = lon;
MKPointAnnotation *annotation = [[MKPointAnnotation alloc] init];
annotation.coordinate = coordinate;
annotation.title = [rows objectAtIndex:0];
annotation.subtitle = [rows objectAtIndex:4];
//[_mapView addAnnotation:annotation];
[self.mapView addAnnotation:annotation];
}
}
Here is the MKAnnotationsview code
#import <UIKit/UIKit.h>
#import <MapKit/MKFoundation.h>
// Post this notification to re-query callout information.
MK_EXTERN NSString * const MKAnnotationCalloutInfoDidChangeNotification;
#if (__IPHONE_4_0 <= __IPHONE_OS_VERSION_MAX_ALLOWED)
enum {
MKAnnotationViewDragStateNone = 0, // View is at rest, sitting on the map.
MKAnnotationViewDragStateStarting, // View is beginning to drag (e.g. pin lift)
MKAnnotationViewDragStateDragging, // View is dragging ("lift" animations are complete)
MKAnnotationViewDragStateCanceling, // View was not dragged and should return to it's starting position (e.g. pin drop)
MKAnnotationViewDragStateEnding // View was dragged, new coordinate is set and view should return to resting position (e.g. pin drop)
};
typedef NSUInteger MKAnnotationViewDragState;
#endif // #if (__IPHONE_4_0 <= __IPHONE_OS_VERSION_MAX_ALLOWED)
#class MKAnnotationViewInternal;
#protocol MKAnnotation;
MK_CLASS_AVAILABLE(NA, 3_0)
#interface MKAnnotationView : UIView
{
#private
MKAnnotationViewInternal *_internal;
}
- (id)initWithAnnotation:(id <MKAnnotation>)annotation reuseIdentifier:(NSString *)reuseIdentifier;
#property (nonatomic, readonly) NSString *reuseIdentifier;
// Classes that override must call super.
- (void)prepareForReuse;
#property (nonatomic, retain) id <MKAnnotation> annotation;
#property (nonatomic, retain) UIImage *image;
// By default, the center of annotation view is placed over the coordinate of the annotation.
// centerOffset is the offset in screen points from the center of the annotion view.
#property (nonatomic) CGPoint centerOffset;
// calloutOffset is the offset in screen points from the top-middle of the annotation view, where the anchor of the callout should be shown.
#property (nonatomic) CGPoint calloutOffset;
// Defaults to YES. If NO, ignores touch events and subclasses may draw differently.
#property (nonatomic, getter=isEnabled) BOOL enabled;
// Defaults to NO. This gets set/cleared automatically when touch enters/exits during tracking and cleared on up.
#property (nonatomic, getter=isHighlighted) BOOL highlighted;
// Defaults to NO. Becomes YES when tapped on in the map view.
#property (nonatomic, getter=isSelected) BOOL selected;
- (void)setSelected:(BOOL)selected animated:(BOOL)animated;
// If YES, a standard callout bubble will be shown when the annotation is selected.
// The annotation must have a title for the callout to be shown.
#property (nonatomic) BOOL canShowCallout;
// The left accessory view to be used in the standard callout.
#property (retain, nonatomic) UIView *leftCalloutAccessoryView;
// The right accessory view to be used in the standard callout.
#property (retain, nonatomic) UIView *rightCalloutAccessoryView;
// If YES and the underlying id<MKAnnotation> responds to setCoordinate:,
// the user will be able to drag this annotation view around the map.
#property (nonatomic, getter=isDraggable) BOOL draggable NS_AVAILABLE(NA, 4_0);
// Automatically set to MKAnnotationViewDragStateStarting, Canceling, and Ending when necessary.
// Implementer is responsible for transitioning to Dragging and None states as appropriate.
#property (nonatomic) MKAnnotationViewDragState dragState NS_AVAILABLE(NA, 4_0);
// Developers targeting iOS 4.2 and after must use setDragState:animated: instead of setDragState:.
- (void)setDragState:(MKAnnotationViewDragState)newDragState animated:(BOOL)animated NS_AVAILABLE(NA, 4_2);
#end
Here is the Delegate.h codes.....
#import "MapinAppDelegate.h"
#implementation MapinAppDelegate
#synthesize window = _window;
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
// Override point for customization after application launch.
return YES;
}
- (void)applicationWillResignActive:(UIApplication *)application
{
/*
Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.
*/
}
- (void)applicationDidEnterBackground:(UIApplication *)application
{
/*
Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
*/
}
- (void)applicationWillEnterForeground:(UIApplication *)application
{
/*
Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background.
*/
}
- (void)applicationDidBecomeActive:(UIApplication *)application
{
/*
Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
*/
}
- (void)applicationWillTerminate:(UIApplication *)application
{
/*
Called when the application is about to terminate.
Save data if appropriate.
See also applicationDidEnterBackground:.
*/
}
#end
Here are the Delegate.m codes....
#import <UIKit/UIKit.h>
#interface MapinAppDelegate : UIResponder <UIApplicationDelegate>
#property (strong, nonatomic) UIWindow *window;
#end
Use CustomAnnotaion which is inherited by MKAnnotation only, in that class assign your own properties, like locationDetails, locationImage, etc.
To add this information, update your MKAnnotatinView, by implementing this delegate
- (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id )annotation
Example:
http://developer.apple.com/library/ios/#DOCUMENTATION/UserExperience/Conceptual/LocationAwarenessPG/AnnotatingMaps/AnnotatingMaps.html
http://www.highoncoding.com/Articles/805_Consuming_XML_Feed_and_Displaying_Public_Information_on_the_MapView_Control.aspx

My annotations doesn't show the Sub Title in the PIN

in the implementations class charged of displaying PINS, i have reserved two variables (title and sub title), in this example, only the word USA (the title) is displayed when i click on the PIN.
CLLocationCoordinate2D location2D = (CLLocationCoordinate2D){ .latitude = latitudeOfUserLocation, .longitude = longitudeOfUserLocation };
ManageAnnotations *annotation=[[ManageAnnotations alloc]initWithTitle:#"USA" adresseDuTheme:#"Colorado" coordinate:location2D];//only USA is displayed
annotation.pinColor = MKPinAnnotationColorRed; //or red or whatever
[self->mapView addAnnotation:annotation];
MKCoordinateSpan span={.latitudeDelta=1,.longitudeDelta=0.5};
MKCoordinateRegion region={location2D,span};
[mapView setRegion:region];
Although, in ManageAnnotations class, i have reserved two variables for the title and the subtitle.
#interface ManageAnnotations : NSObject<MKAnnotation>{
NSString *_libelle;
NSString *_adresse;
CLLocationCoordinate2D _coordinate;
}
//
#property(nonatomic,assign)MKPinAnnotationColor pinColor;
#property(copy)NSString *libelle;
#property(copy)NSString *adresse;
#property(nonatomic,readonly)CLLocationCoordinate2D coordinate;
-(id)initWithTitle:(NSString*)libelle adresseDuTheme:(NSString*)adresse coordinate:(CLLocationCoordinate2D)coordinate;
#end
#import "ManageAnnotations.h"
#implementation ManageAnnotations
#synthesize pinColor;
#synthesize libelle=_libelle;
#synthesize adresse=_adresse;
#synthesize coordinate=_coordinate;
-(id)initWithTitle:(NSString*)libelle adresseDuTheme:(NSString*)adresse coordinate:(CLLocationCoordinate2D)coordinate{
if((self=[super init])){
_libelle=[libelle copy];
_adresse=[adresse copy];
_coordinate=coordinate;
}
return self;
}
-(NSString*)title{
return _libelle;
}
-(NSString*)subTitle{
return _adresse;
}
#end
The MKAnnotation protocol defines the subtitle property as:
#property (nonatomic, readonly, copy) NSString *subtitle
Note subtitle is all lowercase but your class has subTitle (uppercase T) which the map view will not call.
Change the method declaration to:
-(NSString*)subtitle
change subTitle to subtitle in method declaration and property declaration and it will work.
:) happy coding,

Resources