地図をセットアップする

プラットフォームを選択: Android iOS

iOS でルートをたどるために地図を設定する手順は次のとおりです。

  1. マップビューを初期化する
  2. マップイベントを処理する
で確認できます。

ステップ 1: マップビューを初期化する

ルートをフォローするには、地図表示を初期化する必要があります。

次の例は、GMTCMapView を初期化する方法を示しています。

Swift

/*
 * MapViewController.swift
 */
class ViewController: UIViewController, GMTCMapViewDelegate {
  private var rideSharingMap: GMTCMapView?

  override func viewDidLoad() {
    super.viewDidLoad()

    self.rideSharingMap = GMTCMapView(frame: UIScreen.main.bounds)
    self.rideSharingMap.delegate = self
    self.rideSharingMap?.settings.myLocationButton = true
    self.view.addSubview(self.rideSharingMap!)
    ...
    }
  }

Objective-C

/*
 * MapViewController.h
 */
@interface MapViewController : UIViewController<GMTCMapViewDelegate>
...
@end

/*
 * MapViewController.m
 */
@implementation MapViewController

- (void)viewDidLoad {
  [super viewDidLoad];
  ...
  self.mapView = [[GMTCMapView alloc] initWithFrame:CGRectZero];
  self.mapView.settings.myLocationButton = YES;
  self.mapView.delegate = self;
  ...
}

...

@end

ステップ 2: マップビュー イベントを処理する

マップビューの初期化が完了したので、デリゲートの実装方法は次のとおりです。 を使用して、車両が通行の進行状況に合わせてマップビュー イベントの変更を処理します。

Swift

func mapViewDidInitialize(_ mapview: GMTCMapView) {
  // Handle the update to the state of the map view to browsing.
}

func mapView(_ mapView: GMSMapView, didTapConsumerMarker mapMarker: GMSMarker, markerType: GMTCMapViewMarkerType) -> Bool {
  // Handle the mapView marker was tapped.
}

Objective-C

/*
 * MapViewController.m
 */
#pragma mark - GMTCMapViewDelegate implementation

// Handle state update of map view.
- (void)mapViewDidInitializeCustomerState:(GMTCMapView *)mapview {
  // Handle the update to the state of the map view to browsing.
}

- (void)mapView:(GMSMapView *)mapView
    didTapConsumerMarker:(nonnull GMSMarker *)mapMarker
              markerType:(GMTCMapViewMarkerType)markerType {
  // Handle the mapView marker was tapped.
}

次のステップ