1

リアルタイムのリフレッシュレートでユーザーの現在の場所を追跡する必要があります。そのための2つのソリューションを持つ1つの機能があります。

- (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation
{
    
# ifdef Variant_1
    if(m_currentLocation)
        [m_Map removeAnnotation:m_currentLocation];
    else
        m_currentLocation = [MKPlacemark alloc];
    [m_currentLocation initWithCoordinate:newLocation.coordinate addressDictionary:nil];
    [m_Map addAnnotation:m_currentLocation];
    [m_Map setCenterCoordinate:m_currentLocation.coordinate animated:YES];

# else //Variant_2   
    
    if(m_currentLocation == nil)
     {
     m_currentLocation = [MKPlacemark alloc];
     [m_currentLocation initWithCoordinate:newLocation.coordinate addressDictionary:nil];
     [m_Map addAnnotation:m_currentLocation];
     
     }else
     {
     [m_currentLocation initWithCoordinate:newLocation.coordinate addressDictionary:nil];
     //[m_currentLocation setCoordinate:newLocation.coordinate];
     }
    [m_Map setCenterCoordinate:m_currentLocation.coordinate animated:YES];
# endif      
}

Variant_1うまく機能しますが、速く移動すると、地図上の場所の歌が点滅します。
Variant_2点滅はしませんが、場所は移動しませんが、地図は移動します。
問題はどこだ?

4

1 に答える 1

2

Variant_1 では、既存の注釈の座標を変更するだけでなく、removeAnnotation を実行してから addAnnotation を実行しているため、おそらく点滅します。

Variant_2 では、initWithCoordinateはそれらの座標を持つ新しい MKPlacemark オブジェクトを返します。メソッドを呼び出しているオブジェクトのプロパティは更新されません。

代わりに setCoordinate 行を実行するとどうなりますか?

別の質問は、MKMapView の組み込み機能を使用して現在のユーザーの場所を表示しない理由です。最初にやるだけm_Map.showsUserLocation = YES;。とにかく MKMapView を使用している場合、ユーザーの現在の場所を取得するために CLLocationManager は必要ありません。

マップ ビューのデリゲート メソッドのいずれかを使用して、ユーザーの現在地をマップの中心に配置する必要があると思います。

- (void)mapView:(MKMapView *)mapView didUpdateUserLocation:(MKUserLocation *)userLocation
{
    [mapView setCenterCoordinate:userLocation.location.coordinate animated:YES];
}
于 2010-10-31T19:58:35.417 に答える