2017-05-09 34 views
0

我正在寻找实时对mapkit当前位置点作出反应。我可以使用LocationManager以间隔方式获取位置,但注释以更流畅的方式移动。我想捕捉这个动作。有没有办法观察点UIView或坐标的位置而不是反应,在我的情况下连接到MKPolyline端点。反应到Mapkit对象值变化

回答

0

你需要创建自己的用户的位置图,然后添加对它的观测者:

- (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(ClubPinAnnotation *)annotation { 

    // If the annotation is the user location, create and return our own dot view 
    if ([annotation isKindOfClass:[MKUserLocation class]]) {    
     MKAnnotationView *userView = [[MKAnnotationView alloc] initWithFrame:CGRectMake(-5, -5, 10, 10)]; 
     userView.layer.cornerRadius = 5; 
     userView.backgroundColor = [UIColor blueColor]; 

     // Observe its on-screen position 
     [userView addObserver:self forKeyPath:@"layer.position" options:NSKeyValueObservingOptionNew context:nil]; 

     return userView; 
    } 

    ... continue processing the other map annotations 
} 

再观察屏幕上的脚的位置:

- (void)observeValueForKeyPath:(NSString *)keyPath 
         ofObject:(id)object 
         change:(NSDictionary *)change 
         context:(void *)context { 

    MKAnnotationView *userView = (MKAnnotationView *)object; 

    NSLog(@"User view:%@", userView); 
} 
+0

p.s.对不起,我在Objective-C中回答,但这个想法是一样的。 – norders

0

动画可能是一个插值响应。我的猜测,因为我没有研究支持这一点。

您可以估计动画期间,并将MkPolyline作为动画期间的插值区域上的计算值作为时间的函数。