2013-03-23 2 views
0

CoreLocation обыкновение компилировать из этой линииCoreLocation обыкновение компилировать - та же установка, как другой рабочий проект

LocationAnnotation *annotation = [[LocationAnnotation alloc] initWithTitle:@"Point to home?" andCoordinate:newLocation.coordinate andSubtitle:nil]; 

Я пробовал все, и теперь скучно перекомпоновки coreLoction

Если я комментирую, что строка CoreLocation компилируется отлично.

Я включил CoreLocation и MapKit в фазе сборки, у меня нет рамки поиска путей

Undefined symbols for architecture i386: 
    "_OBJC_CLASS_$_LocationAnnotation", referenced from: 
     objc-class-ref in JobMapVC.o 
ld: symbol(s) not found for architecture i386 
clang: error: linker command failed with exit code 1 (use -v to see invocation) 

Я использовал этот код в другом проекте компилирует хорошо, не то, что мне не хватает?

Главный контроллер

JobMapVC.h

#import <UIKit/UIKit.h> 
#import <MapKit/MapKit.h> 
#import <CoreLocation/CoreLocation.h> 

#import "LocationAnnotation.h" 

@interface JobMapVC : UIViewController <MKMapViewDelegate, CLLocationManagerDelegate> 
{ 
    NSString *address; 

@private 
    CLLocationManager *locationManager; 
} 

@property (nonatomic, strong) NSString *address; 
@property (nonatomic, retain) CLLocationManager *locationManager; 
@property (nonatomic, assign, readwrite) double homeLatitude; 
@property (nonatomic, assign, readwrite) double homeLongitude; 

@property (weak, nonatomic) IBOutlet MKMapView *mapView; 

- (IBAction)dismissMap:(id)sender; 

@end 

JobMapVC.m

#import "JobMapVC.h" 
#import "LocationAnnotation.h" 

@interface JobMapVC() 

@end 

@implementation JobMapVC 
{ 
} 

@synthesize address = _address; 
@synthesize locationManager = _locationManager; 

- (void)viewDidLoad 
{ 
    [super viewDidLoad]; 
    [self searchCoordinatesForAddress:_address]; 
} 


- (void) searchCoordinatesForAddress:(NSString *)inAddress{ 

    NSString *cleanAddress = [[inAddress componentsSeparatedByCharactersInSet:[NSCharacterSet newlineCharacterSet]] componentsJoinedByString:@" "]; 

    NSMutableString *urlString = [NSMutableString stringWithFormat:@"http://maps.googleapis.com/maps/api/geocode/json?sensor=true&address=%@",cleanAddress]; 

    [urlString setString:[urlString stringByReplacingOccurrencesOfString:@" " withString:@"+"]]; 

    NSURL *url = [NSURL URLWithString:urlString]; 
    NSURLRequest *request = [[NSURLRequest alloc] initWithURL:url]; 
    NSError* error; 
    NSURLResponse *response; 
    NSData *returnData = [NSURLConnection sendSynchronousRequest:request returningResponse:&response error:&error]; 

    NSDictionary* georesults = [NSJSONSerialization 
           JSONObjectWithData:returnData 
           options:NSJSONReadingMutableContainers | NSJSONReadingAllowFragments 
           error:&error]; 


    if ([[georesults objectForKey:@"status"] isEqualToString:@"OK"]) 
    { 

     double latitude = [[[[[[georesults objectForKey:@"results"]objectAtIndex:0] objectForKey:@"geometry"]objectForKey:@"location"]objectForKey:@"lat"] doubleValue]; 
     double longitude = [[[[[[georesults objectForKey:@"results"]objectAtIndex:0] objectForKey:@"geometry"]objectForKey:@"location"]objectForKey:@"lng"] doubleValue]; 
     NSLog(@"lat:%f", latitude); 

     [self zoomMapAndCenterAtLatitude:latitude andLongitude:longitude]; 

    } 
} 

- (void) zoomMapAndCenterAtLatitude:(double)latitude andLongitude:(double)longitude 
{ 
    MKCoordinateRegion region; 
    region.center.latitude = latitude; 
    region.center.longitude = longitude; 

    //Set Zoom level using Span 
    MKCoordinateSpan span; 
    span.latitudeDelta = .005; 
    span.longitudeDelta = .005; 
    region.span = span; 

    //Move the map and zoom 
    [_mapView setRegion:region animated:YES]; 

    // Map pin 

    CLLocation *newLocation = [[CLLocation alloc] initWithLatitude:latitude longitude:longitude]; 

    // THIS LINE STOP coreLocation from compiling !!! 
    LocationAnnotation *annotation = [[LocationAnnotation alloc] initWithTitle:@"Point to home?" andCoordinate:newLocation.coordinate andSubtitle:nil]; 

    [self.mapView addAnnotation:annotation]; 
    [self.mapView selectAnnotation:annotation animated:YES]; 

} 

- (void)locationManager:(CLLocationManager *)manager didFailWithError:(NSError *)error { 
    NSLog(@"locationManager:%@ didFailWithError:%@", manager, error); 

    if (error.code == kCLErrorDenied) 
    { 
     UIAlertView *alert = [[UIAlertView alloc] 
           initWithTitle:@"Error!" 
           message:@"This can not work without location services enabled" 
           delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil]; 
     [alert show]; 
    } 
} 


- (IBAction)dismissMap:(id)sender 
{ 
    [self dismissModalViewControllerAnimated:YES]; 
} 

- (void)didReceiveMemoryWarning 
{ 
    [super didReceiveMemoryWarning]; 
} 

@end 

Файл LocationAnnotation, который я использовал именно так, как это в другом проекте без каких-либо проблем

LocationAnnotation.h

#import <Foundation/Foundation.h> 
#import <MapKit/MapKit.h> 

@interface LocationAnnotation : NSObject <MKAnnotation> { 
} 
@property (strong) NSString *title; 
@property (strong) NSString *subtitle; 

- (id)initWithTitle:(NSString *)ttl andCoordinate:(CLLocationCoordinate2D)c2d andSubtitle:(NSString *)sbttl; 

@end 

LocationAnnotation.m

#import "LocationAnnotation.h" 

@implementation LocationAnnotation 

@synthesize title, subtitle, coordinate; 

- (id)initWithTitle:(NSString *)ttl andCoordinate:(CLLocationCoordinate2D)c2d andSubtitle:(NSString *)sbttl { 
    if ((self = [super init])) { 
     title = ttl; 
     subtitle = sbttl; 
     coordinate = c2d; 
    } 
    return self; 
} 

@end 

Странная вещь является - (ID) initWithTitle линия обыкновение цвет синтаксис правильно. Этот код работает в одном проекте, но не в другом ... ?? !!

+4

ли LocationAnnotation.m' в список 'под YourTarget -> Построение фаз -> Скомпилировать источники? Или флажок отмечен в одной из ваших целей в «Инспекторе файлов» для «LocationAnnotation.m»? – Sebastian

ответ

1

Ваш код компилируется, это компоновщик, который сообщает о проблеме. Линкер не может найти ваш класс LocationAnnotation, потому что он, вероятно, не был скомпилирован. Выберите LocationAnnotation.m в Xcode и в инспекторе Файла (в правом лотке) и убедитесь, что файл является членом вашей цели:

select target membership

Смежные вопросы