8

私は現在のユーザーの場所のカスタム注釈画像を読み込んでいます。バックグラウンドで1秒ごとに現在のユーザーの場所を更新しています。私はこのちらつき効果を避けるために、map.Howに追加する前に、次のコードMapviewでの注釈画像のスムーズな移動

MKCoordinateRegion region; 
MKCoordinateSpan span; 
span.latitudeDelta=0.002; 
span.longitudeDelta=0.002; 
CLLocationCoordinate2D location; 
location.latitude=[lat doubleValue]; 
location.longitude=[longt doubleValue]; 
region.span=span; 
region.center=location; 
addAnnotation=[[AddressAnnotation alloc]initWithCoordinate:location]; 
[email protected]"You are here"; 
[self.mapView removeAnnotations:self.mapView.annotations]; 
[self.mapView addAnnotation:addAnnotation]; 
[self.mapView setRegion:region animated:TRUE]; 
[self.mapView regionThatFits:region]; 

しかしたびにカスタムアノテーション画像が点滅を使用してマップを更新しています現在latutudeと経度を更新した後

NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; 
[self performSelectorOnMainThread:@selector(tempupdate) withObject:nil waitUntilDone:NO]; 
[pool release]; 

-(void)tempupdate 
{ 
    NSLog(@"callToLocationManager"); 
    mylocationManager = [[CLLocationManager alloc]init]; 
    NSLog(@"locationManagerM = %@",mylocationManager); 
    mylocationManager.delegate = self; 
    mylocationManager.desiredAccuracy = kCLLocationAccuracyBest; 
    mylocationManager.distanceFilter = 500; 
    [mylocationManager startUpdatingLocation]; 
} 

答えて

3

私はまだこれをテストしていませんが、あなたのコードを簡単に見てみると、アノテーションを削除して新しいアノテーションを追加することに問題があると思います。

既に添付されているアノテーションのプロパティを編集しましたか?

NSArray* curAnnotations = [mapView annotations]; 
AddressAnnotation* aa = [curAnnotations lastObject]; // I am assuming you only have 1 annotation 
aa.mTitle = @"You are here"; // or don't do this if it never changes 
[aa setCoordinate:location]; 

注:アップルドキュメント、特にドラッグしたり、頻繁な更新をサポートするために使用されるべきものとして「setCoordinate」メソッドを呼び出します。

+0

私はあなたが私は何をすべき詳細に教えてくださいできますか?問題は、マップビュー上の注釈を削除し、追加することであるが、これを行うには、他の方法があると知っていますか? –

+0

サンプルコード – MobileVet

+0

で私の答えを編集しました。お返事ありがとうございます。 –

1

マップから注釈を削除しないでください。代わりに、UIView beginAnimations-commitAnimationsブロックの注釈座標を変更してください。

それはこのようになります:

[UIView beginAnimations:@"yourAnimationName" context:nil]; 
[UIView setAnimationDuration:1.0]; 
[yourAnnotation setCoordinate:yourNewCoordinate]; 
[UIView commitAnimations]; 

それはスムーズに注釈を移動します。

BR、 マルチンSzulc

+0

それは私のために働いた、ありがとう! – FreeNickname

+0

速い3私はこれを行い、それは働いた: – rara

0
//SWIFT 3 
UIView.beginAnimations("yourname", context: nil) 
UIView.setAnimationDuration(1.0) 
yourpin.coordinate = MKCoordinateForMapPoint(mycoordinate) 
UIView.commitAnimations() 
関連する問題