8

ユーザーの現在の場所のカスタム注釈画像をロードしました。バックグラウンドで 1 秒ごとに現在のユーザーの場所を更新しています。

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];
}

現在の緯度と経度を更新した後、次のコードを使用してマップを更新しています

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];
addAnnotation.mTitle=@"You are here";
[self.mapView removeAnnotations:self.mapView.annotations];
[self.mapView addAnnotation:addAnnotation];
[self.mapView setRegion:region animated:TRUE];
[self.mapView regionThatFits:region];

しかし、マップに追加する前にカスタム注釈画像が点滅するたびに、このちらつき効果を回避するにはどうすればよいですか?

4

3 に答える 3

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];

注: Apple Docs では、ドラッグや頻繁な更新をサポートするために使用する必要があるものとして、「setCoordinate」メソッドを明確に呼び出しています。

于 2012-03-13T20:37:44.213 に答える
1

マップから注釈を削除してはなりません。代わりに、UIView beginAnimations-commitAnimations ブロックで注釈座標を変更します。

次のようになります。

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

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

BR、マルシン・シュルク

于 2012-04-06T07:29:38.840 に答える