Thiết lập bản đồ

Chọn nền tảng: Android iOS

Để thiết lập bản đồ để theo dõi một chuyến đi trong iOS, hãy hoàn thành các bước sau:

  1. Khởi chạy chế độ xem bản đồ
  2. Xử lý sự kiện trên bản đồ

Bước 1: Khởi chạy chế độ xem bản đồ

Để theo dõi một chuyến đi, bạn phải khởi chạy chế độ xem bản đồ.

Ví dụ sau đây trình bày cách khởi tạo 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

Bước 2: Xử lý sự kiện xem bản đồ

Giờ đây, bạn đã khởi chạy chế độ xem bản đồ, sau đây là cách triển khai thực thể đại diện để xử lý các thay đổi của sự kiện ở chế độ xem bản đồ khi xe đi trong suốt hành trình.

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.
}

Các bước tiếp theo