9

iPhone 3GS の「マップ」アプリで、通常は自分の位置を示すアイコンを 2 回クリックすると、青い点がヘッドランプからの光線のように見えます。基本的に、マップ上で自分が向いている方向を示し、画像を回転させます。によると。

このオプションは MapKit MapView を使用して利用できますか?

次のようなもので見出しを取得できることを知っています

- (void)locationManager:(CLLocationManager *) manager didUpdateHeading:(CLHeading *) newHeading {

// 精度が有効な場合、イベントを処理します。

if (newHeading.headingAccuracy > 0) {

    CLLocationDirection theHeading = newHeading.magneticHeading;
    ...
}

}

しかし、Mapkit で素晴らしいヘッドランプ効果を得る方法がわかりません。また、ドキュメントもないようです。

何か案は?

4

5 に答える 5

6

ユーザー追跡モードを追加することも役立ちます。私は遅れていることを知っていますが、おそらく私のような他の開発者への助けになります:)

self.mapView.userTrackingMode = RMUserTrackingModeFollowWithHeading;
于 2013-11-17T13:03:18.307 に答える
4

私は解決策を見つけました:

利用可能な見出し情報を使用して地図を回転させます

[mapView setTransform:CGAffineTransformMakeRotation(heading.magneticHeading * M_PI / -180.0)];

したがって、「ビーム」は常にデバイスの上部を指します。マップの上に ImageView を表示し、locationManager:didUpdateToLocation:fromLocation: の位置を変更するだけです。

- (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation {
        // scroll to new location
    MKCoordinateRegion region = MKCoordinateRegionMakeWithDistance(newLocation.coordinate, 2000, 2000);
    [self.mapView setRegion:region animated:YES];

        // set position of "beam" to position of blue dot
    self.headingAngleView.center = [self.mapView convertCoordinate:newLocation.coordinate toPointToView:self.view];
        // slightly adjust position of beam
    self.headingAngleView.frameTop -= self.headingAngleView.frameHeight/2 + 8;
 }

ここで、frameTop と frameHeight は、frame.origin.y と frame.size.height のショートカットです。理想的ではなく、ドットの位置が変わると少し欠けることがありますが、うまくいくソリューションに満足しています。

これをすべて行う私の OpenSource フレームワーク MTLocation を見てください (および他の多くのクールなマップ関連のもの):

MT場所

于 2011-02-08T20:13:35.320 に答える
3

他の回答のローテーション ロジックは適切ですが、ロケーション マネージャーのデリゲート メソッドに依存しても、適切な解決策にはなりません。「ビーム」画像が青い点と同じ場所にあることはめったになく、頻繁に跳ね返ります。

最良の解決策は、青いドット ビューへの参照を取得し、「ビーム」イメージをサブビューとして追加することです。ビームが上にあり、その周りが透明な正方形のビーム イメージを使用しました。青い点が画像の中心にあると想像してください。


// An MKMapViewDelegate method. Use this to get a reference to the blue dot annotation view as soon as it gets added
- (void)mapView:(MKMapView *)aMapView didAddAnnotationViews:(NSArray *)views {

    for (MKAnnotationView *annotationView in views) {

        // Get the user location view, check for all of your custom annotation view classes here
        if (![annotationView isKindOfClass:[MKPinAnnotationView class]])
        {
            self.userLocationAnnotationView = annotationView;
            gotUsersLocationView = YES;
        }
    }
}


// Adds the 'viewPortView' to the annotation view. Assumes we have a reference to the annotation view. Call this before you start listening to for heading events.
- (void)addViewportToUserLocationAnnotationView {
    TTDASSERT(self.userLocationAnnotationView != nil);
    if (self.userLocationAnnotationView == nil) {
        // No reference to the view, can't do anything
        return;
    }

    if (self.viewPortView == nil) {
        self.viewPortView = [[[UIImageView alloc] initWithImage:[UIImage imageNamed:@"map_viewport.png"]] autorelease];
    }

    [self.userLocationAnnotationView addSubview:self.viewPortView];
    [self.userLocationAnnotationView sendSubviewToBack:self.viewPortView];

    self.viewPortView.frame = CGRectMake((-1 * self.viewPortView.frame.size.width/2) + self.userLocationAnnotationView.frame.size.width/2,
                                         (-1 * self.viewPortView.frame.size.height/2) + self.userLocationAnnotationView.frame.size.height/2,
                                         self.viewPortView.frame.size.width,
                                         self.viewPortView.frame.size.height);
}
于 2011-03-18T15:15:45.137 に答える
2

実装していませんが、少し役立つかもしれませんが、1つの方法を考えることができます。

  1. まず、選択したポインターを含む画像が必要です。このポインターは上向き 90 度を指している必要があります。
  2. MapKit で現在の位置マーカーをオフにします。
  3. x と y の値をdidUpdateHeading使用して、方向の角度を計算します。
  4. この角度を使用して、ポインターの画像を回転させます
  5. この回転した画像をマップの注釈ピンとして使用します。
  6. ポインターの位置を頻繁に更新する必要があります。

上記のアプローチに対する提案/変更を投稿してください。

于 2010-06-22T13:39:10.340 に答える
2

Swift 3 の実装

mapView.userTrackingMode = MKUserTrackingMode.followWithHeading
于 2016-10-05T09:54:25.450 に答える