1

현재 위치에 대한 사용자 정의 핀을 추가하려하지만 위치가 업데이트되지 않습니다. 심지어 내가 return nil; 모든 것을 설정하면, 그러나 setShowsUserLocation = YES;사용자 정의 curent 위치 주석 핀이 코어 위치로 업데이트되지 않습니다.

- (id)initWithAnnotation:(id <MKAnnotation>)annotation reuseIdentifier:(NSString *)reuseIdentifier { 

    self = [super initWithAnnotation:annotation reuseIdentifier:reuseIdentifier]; 
    if ([[annotation title] isEqualToString:@"Current Location"]) { 
     self.image = [UIImage imageNamed:[NSString stringWithFormat:@"cursor_%i.png", [[Session instance].current_option cursorValue]+1]]; 
    } 

을 설정 한 후 잘 작동하지만 사용자 지정 이미지를 잃게됩니다. 나는 이것을 실제로 원한다. 어떤 도움이라도 대단히 감사하겠습니다.

답변

1

위에서 본 것처럼 setShowsUserLocation 플래그는 기본 파란색 거품을 사용하는 현재 위치 만 표시합니다.

여기에서 수행해야 할 작업은 전화로 위치 업데이트를 수신하고 수동으로 주석의 위치를 ​​변경하는 것입니다.

- (void)locationManager:(CLLocationManager *)manager 
    didUpdateToLocation:(CLLocation *)newLocation 
      fromLocation:(CLLocation *)oldLocation 
{ 
    // update annotation position here 
} 

내가 프로토콜을 준수하는 클래스, 위치 표시를 가지고, 좌표의 위치를 ​​변경하려면 : 위치 관리자는 업데이트의 위임을 통지 할 때마다 당신은 CLLocationManager 인스턴스를 생성하여이 작업을 수행하고 주석을 제거하고 교체 할 수 있습니다 MKAnnotation는 :

//--- .h --- 

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

@interface Placemark : NSObject <MKAnnotation> { 
} 

@property (nonatomic, readonly) CLLocationCoordinate2D coordinate; 
@property (nonatomic, retain) NSString *strSubtitle; 
@property (nonatomic, retain) NSString *strTitle; 

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

@end 

//--- .m --- 

@implementation Placemark 

@synthesize coordinate; 
@synthesize strSubtitle; 
@synthesize strTitle; 

- (NSString *)subtitle{ 
    return self.strSubtitle; 
} 
- (NSString *)title{ 
    return self.strTitle; 
} 

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

@end 

그런 다음 내지도보기 컨트롤러에서 내가 가진 주석 배치 : 나는 주석을 다시 그릴 시도

- (void) setPlacemarkWithTitle:(NSString *) title andSubtitle:(NSString *) subtitle forLocation: (CLLocationCoordinate2D) location { 

    //remove pins already there... 
    NSArray *pins = [mapView annotations]; 

    for (int i = 0; i<[pins count]; i++) { 
     [mapView removeAnnotation:[pins objectAtIndex:i]]; 
    } 

    Placemark *placemark=[[Placemark alloc] initWithCoordinate:location]; 
    placemark.strTitle = title; 
    placemark.strSubtitle = subtitle; 
    [mapView addAnnotation:placemark]; 
    [self setSpan]; //a custom method that ensures the map is centered on the annotation 
} 
+0

을하지만 점의 위치를 ​​변경합니다. 주석에 새 위치를 설정하는 방법에 대해 너무 확신 할 수 없습니까? – Frank

+0

이전 앱에서 사용한 코드를 해제하고 위의 대답에서 업데이트했습니다. 잠시 후에 (iOS 3.0!) 작성되었지만 여전히 황금색이어야합니다. 희망이 도움이됩니다! – Sig

+0

예, 많은 도움이되었습니다. MKUserLocation을 사용자 지정 MKAnnotation으로 완전히 대체해야했습니다. 나는 그것을 다른 곳으로 보냈는데 그것을 전체적으로 대체 할 생각을하지 못했다. – Frank

관련 문제