2011-09-09 3 views
0

저는 Apple의 CurrentAddress 샘플 코드로 놀고 있었고 trueHeading 속성을 사용하여 사용자가 향하고있는 방향을 결정하려고했습니다. 그 점은 충분히 간단하지만, 현재 위치 점 위에 투명한 PNG를 표시하고 나침반을 시뮬레이션하기 위해 회전시키고 싶었습니다. 것으로,현재 위치의 맨 위에 투명 PNG가 겹쳐져 있습니다. 파란색 점

@implementation MapViewController 

@synthesize mapView, reverseGeocoder, getAddressButton; 

- (void)viewDidLoad 
{ 
    [super viewDidLoad]; 
    mapView.showsUserLocation = YES; 
} 



- (IBAction)reverseGeocodeCurrentLocation 
{ 
    self.reverseGeocoder = 
     [[[MKReverseGeocoder alloc] initWithCoordinate:mapView.userLocation.location.coordinate] autorelease]; 
    reverseGeocoder.delegate = self; 
    [reverseGeocoder start]; 
} 

- (void)reverseGeocoder:(MKReverseGeocoder *)geocoder didFailWithError:(NSError *)error 
{ 
    NSString *errorMessage = [error localizedDescription]; 
    UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"Cannot obtain address." 
                 message:errorMessage 
             cancelButtonTitle:@"OK" 
               otherButtonTitles:nil]; 
    [alertView show]; 
    [alertView release]; 
} 

- (void)reverseGeocoder:(MKReverseGeocoder *)geocoder didFindPlacemark:(MKPlacemark *)placemark 
{ 
    PlacemarkViewController *placemarkViewController = 
     [[PlacemarkViewController alloc] initWithNibName:@"PlacemarkViewController" bundle:nil]; 
    placemarkViewController.placemark = placemark; 
    [self presentModalViewController:placemarkViewController animated:YES]; 
} 

- (void)mapView:(MKMapView *)mapView didUpdateUserLocation:(MKUserLocation *)userLocation 
{ 
    // we have received our current location, so enable the "Get Current Address" button 
    [getAddressButton setEnabled:YES]; 
    NSString *north = [NSString stringWithFormat:@"%f", self.mapView.userLocation.heading.trueHeading]; 
    NSLog(@"here: %@", north); 
} 

@end 

나는 파란색 점의 정확한 위치에 PNG를 오버레이하고 사용자가 이동하면 점 다음 (거기를 유지할 수 있습니다 방법 :

여기에 내가 현재 가지고 아주 기본적인 코드입니다)입니까?

답변

1

요점은 mapView:viewForAnnotation: 대리자 메서드를 구현하고 자신의 것이 아닌 주석 개체를 찾아야한다는 것입니다. 코드를 잘 살펴보세요.

- (MKAnnotationView *)mapView:(MKMapView *)map viewForAnnotation:(id <MKAnnotation>)annotation { 
    NSString static *defaultID = @"defaultID"; 
    NSString static *userLocationID = @"userLocationID"; 

    if ([annotation isKindOfClass:[MyAnnotation class]]) { 
     // your code here 
    } else { 
     MKAnnotationView *annotationView = [map dequeueReusableAnnotationViewWithIdentifier:userLocationID]; 
     if (!annotationView) { 
      annotationView = [[[MKAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:userLocationID] autorelease]; 
      annotationView.image = [UIImage imageNamed:@"UserLocationIcon.png"]; 
     } 
     return annotationView; 
    } 
} 
+0

너무 오래 걸려서 죄송합니다. 몇 가지 긴급한 문제가있었습니다. OK, 간단하게 보이지만, "your code here"부분에 오버레이를 추가하려고합니다. –

+0

아니요, "여기에 코드를 입력하십시오"는 직접 추가 한 주석 (물론 추가 한 경우)의 부분이며, 다른 부분을 구현해야합니다. 보시다시피, "UserLocationIcon.png"이 있는데, 이것은 기본 청색 사용자 핀 대신 표시됩니다. –

+0

감사합니다. * annotationView에 대한 그림자 선언 오류도 발생합니다. 어떤 아이디어? –

관련 문제