2010-12-06 116 views
1

我有一個mapview,我用CoreLocation更新我的當前位置,但我也有使用userLocation的檢查。userLocationVisble返回錯誤

我還沒有找到替代方案來解決我的問題 但由於某種原因,我無法使用userLocationVisible來隱藏藍點。

當我進入我的MapView時,我啓動了locationManager,但在更新我的位置之前,出現藍點,並且我的pin不出現。

我試過使用自定義的MKAnnotation,並從DidUpdateToLocation的newLocation初始化座標。但是,當我運行此我得到:

-[CustomPlacemark setCoordinate:]: unrecognized selector sent to instance 0x1de6c0 

這是我CustomPlacemark:

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

@interface CustomPlacemark : NSObject<MKAnnotation> { 
    CLLocationCoordinate2D coordinate; 
    NSString *title; 
    NSString *subtitle; 
} 
@property (nonatomic, readonly) CLLocationCoordinate2D coordinate; 
@property (nonatomic, retain) NSString *title; 
@property (nonatomic, retain) NSString *subtitle; 

-(id)initWithCoordinate:(CLLocationCoordinate2D) coordinate; 
- (NSString *)subtitle; 
- (NSString *)title; 
@end 

#import "CustomPlacemark.h" 

@implementation CustomPlacemark 
@synthesize coordinate; 
@synthesize title, subtitle; 

-(id)initWithCoordinate:(CLLocationCoordinate2D) c{ 
    self=[super init]; 
    if (self!=nil) { 
     coordinate=c; 
    } 
    return self; 
} 

-(NSString*)title{ 
    return title; 
} 

-(NSString*)subtitle{ 
    return subtitle; 
} 

-(void) dealloc 
{ 
    [title release]; title = nil; 
    [subtitle release]; subtitle = nil; 
    [super dealloc]; 
} 
@end 

可有人還告訴我,爲什麼我不能使用UserLocationVisible?

回答

1

座標是customplacemark類的只讀屬性。所以你不能設置座標屬性。設置座標屬性使其讀寫。

變線@property (nonatomic, readonly) CLLocationCoordinate2D coordinate;

@property (nonatomic, readwrite) CLLocationCoordinate2D coordinate;

0

做這將是initWithCoordinate而不是使屬性讀寫

0

正確的方法,當你設置後,藍色圓點showsUserLocation = YES;如果要隱藏藍點,請將其設置爲NO。或者,您可以使用CoreLocation確定用戶的位置是否在屏幕上可見,並啓用showsUserLocation爲YES。

此外,藍點是符合MKAnnotation協議的特殊註記類MKUserLocation。如果您將任何消息發送到您自己的類的註釋對象,則可能需要排除MKUserLocation註釋對象。

如果你想知道如何專門處理你的自定義註釋對象而不發送不正確的消息給MKUserLocation類,讓我知道,我有我可以發送的代碼。