ตั้งค่าแผนที่

เลือกแพลตฟอร์ม 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.
}

ขั้นตอนถัดไป