2013-05-01 2 views
2

CLLocationManager의 좌표를 사용하여지도에 사용자의 위치를 ​​표시하고 있습니다. 지도를 이동하거나 확대 할 때마다 사용자 위치 핀 (소나 효과가있는 파란색 핀)이 계속 사라지고 다시지도에 다시 애니메이션이 적용됩니다. (나는 수중 음파 탐지기 애니메이션 효과를 언급하지 않고 있습니다. 파란색 점은 문자 그대로 사라지고 다시 움직입니다).iOS - Mapkit은지도보기가 변경 될 때마다 사용자 위치의 애니메이션을 유지합니다.

지도를 스크롤/확대/축소 할 때 다른 방법을 호출하지 않습니다. 중단 점을 사용 는 만 반환 전무는지도의 대리자 메서드에서 호출됩니다

- (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id <MKAnnotation>)annotation 
{ 
    //User's Pin 
    if([annotation class] == MKUserLocation.class) { 
     return nil; 
    } 

....rest of my code here, nothing else is called as I am only plotting user at this time... 
} 

답변

0

잡기가 그려하지 그래서 viewForAnnotation 위임 방법에 따라 기본 사용자 위치 주석. 부울을 사용하여 켜기/끄기를 전환하거나 LocationManager와 함께 사용자 정의 주석을 만들 수 있습니다. 이 링크는 바른 길에 당신을 얻을해야합니다 내 원래의 대답에

User Location Anno

+0

질문에 혼란이 있다고 생각합니다. 업데이트 된 원본 게시물을 참조하십시오. 나는 사용자의 "파란색 점"을 바꾸려고하지 않습니다. 나는 왜 그것이 계속 사라지는지 궁금해서지도가 스크롤되거나 확대 될 때마다 다시 애니메이션을 적용합니다. – JimmyJammed

3

을, 나는 목표는 당신이 showUserLocation = YESuserTrackingMode = MKUserTrackingModeFollowMKMapView를 사용할 때 얻을 깜박이는 파란색 점을 교체하는 것이라고 생각했다. 그래서 이미지 나 표준 핀으로 대체하는 방법을 보여주었습니다.

그러나 현재 위치를 나타내는 파란색 점이 아니라, 애니메이션이 중단되어 사용자가 이동하고지도에서 확대/축소 할 때 나타나고 사라지는 것이 밝혀졌습니다.

removeAnnotations을 호출하고 모든 주석 (시스템에서 MKUserLocation 주석을 생성 한 것을 포함하여)을 제거하면이 동작을 보았습니다. showUserLocation을 끈 다음 다시 켜면이 동작을 보았습니다.

OP는 이러한 상황 중 어느 것도 적용되지 않는다고 지적하지만 향후 독자에게는 이러한 문제가 발생할 수있는 몇 가지 고려 사항이 있습니다.


원래 대답은 :

가장 쉬운 대답은 확실히 컨트롤러가 MKMapView에 대한 delegate되어 있는지 확인 한 다음 MKUserLocation을 감지하는 viewForAnnotation을 정의하고, 당신이 원하는대로와 주석 뷰를 대체하는 것입니다. 당신이

- (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id<MKAnnotation>)annotation 
{ 
    if ([annotation isKindOfClass:[MKUserLocation class]]) 
    { 
     if ([annotation isKindOfClass:[MKUserLocation class]]) 
     { 
      NSString *annotationIdentifier = @"userlocation"; 
      MKAnnotationView *annotationView = [mapView dequeueReusableAnnotationViewWithIdentifier:annotationIdentifier]; 
      if (annotationView) 
      { 
       annotationView.annotation = annotation; 
      } 
      else 
      { 
       annotationView = [[MKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:annotationIdentifier]; 
      } 

      return annotationView; 
     } 
    } 

    // again, if you had other annotation types, such as MKPointAnnotation, 
    // handle them here 

    if ([annotation isKindOfClass:[MKPointAnnotation class]]) 
    { 
     ... 
    } 

    return nil; 
} 
+0

위의 예는'MKMapView'의 "show user location"기능을 사용했다고 가정합니다. – Rob

+0

그래, 내 컨트롤러가 델리게이트이고, 다른 모든 핀들은 잘 보여주고 설정 중단 점은 상황이이 메소드에서 호출되는 것을 보여준다. – JimmyJammed

+0

이것은 사용자 위치에 대해 현재 수행하고있는 작업입니다. if ([annotation isKindOfClass : [MKUserLocation class]] { return nil; } – JimmyJammed

0

경우 : 당신이, 당신이 수를 표준 핀을 보여주고 싶었다 경우,

- (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id<MKAnnotation>)annotation 
{ 
    if ([annotation isKindOfClass:[MKUserLocation class]]) 
    { 
     NSString *annotationIdentifier = @"userlocation"; 
     MKAnnotationView *annotationView = [mapView dequeueReusableAnnotationViewWithIdentifier:annotationIdentifier]; 
     if (annotationView) 
     { 
      annotationView.annotation = annotation; 
     } 
     else 
     { 
      annotationView = [[MKAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:annotationIdentifier]; 
      annotationView.image = [UIImage imageNamed:@"user.png"]; 
     } 

     return annotationView; 
    } 

    // again, if you had other annotation types, such as MKPointAnnotation, 
    // handle them here 

    if ([annotation isKindOfClass:[MKPointAnnotation class]]) 
    { 
     ... 
    } 

    return nil; 
} 

또는 : 당신은 당신이 보여주고 싶었 @"user.png" 이미지를 가지고 예를 들어, 그것은처럼 보일 수 있습니다 mapciew.showsUserLocation = true; 표준을 사용하여 사용자의 위치를 ​​그렸고 위치가 맥동하지 않고 화면을 미끄러 뜨리면 이는 아마도 viewForAnnotation 방법 때문일 것입니다. 추가하는 핀에만 애니메이션을 적용하고지도 뷰에 추가하는 사용자의 위치는 애니메이션으로 지정하지 않도록합니다.

- (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id<MKAnnotation>)annotation 
{ 
    if ([annotation isKindOfClass:[MKUserLocation class]]) 
    { 
     return nil; 
    } 
    //do stuff to the annotations that you added 
} 
+0

예, 현재 진행 중입니다. 그러나지도를 이동/확대 할 때마다 사용자 위치를 다시로드하고 다시 애니메이션을 적용합니다 (파란색 점이 사라지고 애니메이션이 다시 시작되어 맥박이 시작됩니다). 이것은 내가 원하지 않는 "재 장전"함의를 준다. 제안? – JimmyJammed

+0

나는 "reanimating in"이 무슨 뜻인지 잘 모르겠습니다. Apple지도에서 추적 기능을 켜고 끌 때 점이 나타나거나 사라지면 어디에서나 움직이지 않습니다. 코드에서 수행하는 작업은 무엇입니까? 지도에서 팬 또는 확대/축소를 종료하는 모든 트리거? 코드에서 얼마나 많은 위치에서 추적 기능을 켜고 끕니까? 그들이 예기치 않게 불려지는지 확인해야합니다. – Craig

+0

그래, 해결할 수있는 새로운 버그가 발견되었습니다. 지도에 더미 핀을 추가했습니다. 초기로드시에는 모두 표시됩니다. 지도를 스크롤/확대/축소하면 모두 사라지고 다시 나타나지 않습니다. 내가 언급하고있는 "다시 애니메이션하기"는 파란색 점이 사라지고 음파 탐지기의 거품이 나타나고 큰 파란색 점이 나타나고 음파 탐지기의 거품이 줄어들고 정상적으로 움직입니다. – JimmyJammed