위에서 본 것처럼 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
}
출처
2011-03-03 03:30:13
Sig
을하지만 점의 위치를 변경합니다. 주석에 새 위치를 설정하는 방법에 대해 너무 확신 할 수 없습니까? – Frank
이전 앱에서 사용한 코드를 해제하고 위의 대답에서 업데이트했습니다. 잠시 후에 (iOS 3.0!) 작성되었지만 여전히 황금색이어야합니다. 희망이 도움이됩니다! – Sig
예, 많은 도움이되었습니다. MKUserLocation을 사용자 지정 MKAnnotation으로 완전히 대체해야했습니다. 나는 그것을 다른 곳으로 보냈는데 그것을 전체적으로 대체 할 생각을하지 못했다. – Frank