برای تنظیم نقشه برای دنبال کردن یک سفر در iOS، مراحل زیر را انجام دهید:
مرحله ۱: مقداردهی اولیه نمای نقشه
برای دنبال کردن یک سفر، باید نمای نقشه را راهاندازی کنید.
مثال زیر نحوه مقداردهی اولیه GMTCMapView را نشان میدهد.
سویفت
/*
* 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!)
...
}
}
هدف-سی
/*
* 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
مرحله ۲: مدیریت رویدادهای نمای نقشه
اکنون که نمای نقشه را مقداردهی اولیه کردهاید، در اینجا نحوه پیادهسازی یک نماینده برای مدیریت تغییرات رویداد نمای نقشه با پیشرفت وسیله نقلیه در طول سفرش آورده شده است.
سویفت
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.
}
هدف-سی
/*
* 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.
}