Roa
Roa

Reputation: 109

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

Picture

Upvotes: 1

Views: 44

Answers (1)

Rob
Rob

Reputation: 437882

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.

Upvotes: 1

Related Questions