התאמה אישית של ממשק המשתמש ב-iOS

באמצעות Consumer SDK תוכלו להחיל סמנים מותאמים אישית ולנתב קווים פוליגוניים לעיצוב האפליקציה. רכיבי העיצוב האלה מאפשרים לאפליקציית הצרכן להציג תצוגה מקדימה דינמית של מסלול הרכב.

במדריך הזה מתוארות האפשרויות שזמינות ב-SDK בנכס consumerMapStyleCoordinator. הנכס הזה זמין דרך המחלקה GMTCMapView. הוא מכסה רק את רכיבי ממשק המשתמש, בהנחה שיש לכם אפליקציית צריכה פונקציונליות. למידע על הגדרת השירותים לקצה העורפי שנדרשים לצרכנים SDK, תוכלו לקרוא את המאמר תחילת העבודה עם Fleet Engine.

אתחול האפשרויות להתאמה אישית של ממשק המשתמש

הקריאה החוזרת (callback) המומלצת להגדרה הראשונית של אפשרויות ההתאמה האישית של ממשק המשתמש מוצהרת ב-GMTCMapViewDelegate. הקריאה החוזרת (callback) mapViewDidInitialize מופעלת כשהאובייקט GMTCMapView מוכן לעיבוד המפה. מתאם הסגנונות מאותחל, אבל אין רכיבים בממשק המשתמש.

Swift

/** ViewController.swift */

class ViewController: UIViewController, GMTCMapViewDelegate {

  // MARK: - GMTCMapViewDelegate

  func mapViewDidInitialize(_ mapview: GMTCMapView) {
    // Set the UI customization options here.
  }
}

Objective-C

/** ViewController.m */

@interface ViewController () <GMTCMapViewDelegate>

#pragma mark GMTCMapViewDelegate

- (void)mapViewDidInitialize:(GMTCMapView *)mapview {
  // Set the UI customization options here.
}

סמנים בהתאמה אישית

הדוגמה הבאה משתמשת ב-GMTCMapView להתאמה אישית של סגנונות סמנים. כדי להגדיר את סוג הסמן ואת המאפיינים שלו, משתמשים ב-setMarkerStyleOptions(_:markerType:). אפשרויות הסמנים המותאמים אישית מבטלות את ערכי ברירת המחדל שסופקו על ידי ה-SDK של הצרכן.

Swift

/** ViewController.swift */

private func changeMarkerStyle(
  markerStyleOptions: GMTCMarkerStyleOptions?,
  markerType: GMTCCustomizableMarkerType
) {
  let styleCoordinator = mapView.consumerMapStyleCoordinator
  styleCoordinator.setMarkerStyleOptions(markerStyleOptions, markerType: markerType)
}

/** To restore the default values, call setMarkerStyleOptions(_:markerType:) using nil for the GMTCMarkerStyleOptions parameter.
Here is an example of retrieving the active GMTCMarkerStyleOptions. */

private func retrieveMarkerStyle(markerType: GMTCCustomizableMarkerType) {
  let styleCoordinator = mapView.consumerMapStyleCoordinator

  // The 'markerStyleOptions' contains the stored style options for this marker type.
  let markerStyleOptions = styleCoordinator.markerStyleOptions(for: markerType)
}

Objective-C

/** ViewController.h */

- (void)changeMarkerStyle:(nullable GMTCMarkerStyleOptions *)markerStyleOptions
               markerType:(GMTCCustomizableMarkerType)markerType {
  GMTCConsumerMapStyleCoordinator *styleCoordinator = _mapView.consumerMapStyleCoordinator;
  [styleCoordinator setMarkerStyleOptions:markerStyleOptions markerType:markerType];
}

/** To restore the default values, call setMarkerStyleOptions:markerStyleOptions:markerType: using nil for the GMTCMarkerStyleOptions parameter.
Here is an example of retrieving the active GMTCMarkerStyleOptions. */

- (void)retrieveMarkerStyle:(GMTCCustomizableMarkerType)markerType {
  GMTCConsumerMapStyleCoordinator *styleCoordinator = _mapView.consumerMapStyleCoordinator;

  // The 'markerStyleOptions' contains the stored style options for this marker type.
  GMTCMarkerStyleOptions *markerStyleOptions = [styleCoordinator markerStyleOptionsForType:markerType];
}

סוגי סמנים

הסמנים הבאים זמינים להתאמה אישית:

  • GMTCCustomizableMarkerType.unknown
  • GMTCCustomizableMarkerType.tripPickupPoint
  • GMTCCustomizableMarkerType.tripDropoffPoint
  • GMTCCustomizableMarkerType.tripVehicle
  • GMTCCustomizableMarkerType.intermediateDestination

אפשר להשתמש ב-GMTCCustomizableMarkerType.tripPickupPoint, ב-GMTCCustomizableMarkerType.intermediateDestination וב-GMTCCustomizableMarkerType.tripDropoffPoint כדי להתאים אישית את ציוני הדרך במהלך הנסיעה והתקדמות ההזמנה.

באמצעות GMTCCustomizableMarkerType.tripVehicle, אפשר להתאים אישית את סמל הרכב במהלך הנסיעה ותהליך ההזמנה. סמל הסמן לא משתנה בהתאם לסוג הרכב בפועל בנסיעה.

אפשרויות סימון

המאפיינים הניתנים להתאמה אישית לכל סמן הם קבוצת משנה של המאפיינים שסופקו על ידי מפות Google MarkerOptions. ה-SDK GMTCMarkerStyleOptions נבנה באמצעות מאתחל, ולא ניתן לשנות אותו אחרי שיוצרים אותו. ערכי ברירת מחדל מוגדרים לכל מאפיין, ולכן יש לציין רק ערכים מותאמים אישית.

המאפיינים הבאים זמינים להתאמה אישית:

  • groundAnchor
  • isVisible
  • iconView
  • icon
  • zIndex
  • isFlat

אם מגדירים את isVisible כ-False, הפעולה מקבילה ל "השבתת" הסמן. יש לספק מספיק נתונים כדי לאפשר לכם להשתמש ברכיב ממשק משתמש משלכם במקומו.

דוגמה

Swift

/** MapViewController.swift */

private func updateMarkerUIOptions() {
  // Get the GMTCConsumerMapStyleCoordinator
  let consumerMapStyleCoordinator = mapView.consumerMapStyleCoordinator

  // The marker type that you would like to set custom UI options for.
  let customizableMarkerType = GMTCCustomizableMarkerType.tripVehicle

  // Initializing marker options.
  let markerStyleOptions = GMTCMutableMarkerStyleOptions()
  markerStyleOptions.groundAnchor = kGMSMarkerDefaultGroundAnchor
  markerStyleOptions.icon = icon
  markerStyleOptions.zIndex = 100
  markerStyleOptions.isFlat = false
  markerStyleOptions.isVisible = true

  consumerMapStyleCoordinator.setMarkerStyleOptions(markerStyleOptions, markerType: customizableMarkerType)

  // Reset marker options to default values.
  consumerMapStyleCoordinator.setMarkerStyleOptions(nil, markerType: customizableMarkerType)
}

Objective-C

/** MapViewController.m */

- (void)updateMarkerUIOptions {
  // Get the GMTCConsumerMapStyleCoordinator
  GMTCConsumerMapStyleCoordinator *consumerMapStyleCoordinator = [_mapView consumerMapStyleCoordinator];

  // The marker type that you would like to set custom UI options for.
  GMTCCustomizableMarkerType customizableMarkerType = GMTCCustomizableMarkerTypeTripVehicle;

  // Initializing marker options.
  GMTCMutableMarkerStyleOptions *markerStyleOptions =
      [[GMTCMutableMarkerStyleOptions alloc] init];
  markerStyleOptions.groundAnchor = kGMSMarkerDefaultGroundAnchor;
  markerStyleOptions.icon = icon;
  markerStyleOptions.zIndex = 100;
  markerStyleOptions.isFlat = NO;
  markerStyleOptions.isVisible = YES;

  [consumerMapStyleCoordinator setMarkerStyleOptions:markerStyleOptions markerType:customizableMarkerType];

  // Reset marker options to default values.
  [consumerMapStyleCoordinator setMarkerStyleOptions:nil markerType:customizableMarkerType];
}

עדכונים דינמיים של זמן הגעה משוער לסמני איסוף

כדי ליצור סמן לאיסוף שמציג באופן דינמי את זמן ההגעה המשוער המעודכן מעת לעת, צריך לעדכן את אפשרויות הסגנון של הסמן עבור GMTCCustomizableMarkerType.tripPickupPoint.

דוגמה

Swift

/** MapViewController.swift */

/// Updates the ETA every minute by creating a Timer that repeats every minute.
private func schedulePickupMarkerStyleUpdates() {
  Timer.scheduledTimer(
    timeInterval: 60.0,  // Update marker ETA every minute.
    target: self,
    selector: #selector(updatePickupMarkerETA),
    userInfo: nil,
    repeats: true)
}

/// Updates the marker options for GMTCCustomizableMarkerType.tripPickupPoint for the current time.
@objc private func updatePickupMarkerETA() {
  let consumerMapStyleCoordinator = mapView.consumerMapStyleCoordinator
  let previousOptions = consumerMapStyleCoordinator.markerStyleOptions(for: .tripPickupPoint)

  // Get updated ETA icon.
  let updatedETAIcon = pickupIconForCurrentTime()

  let markerStyleOptions = GMTCMutableMarkerStyleOptions()
  markerStyleOptions.groundAnchor = kGMSMarkerDefaultGroundAnchor
  markerStyleOptions.icon = updatedETAIcon
  markerStyleOptions.zIndex = 100
  markerStyleOptions.isFlat = false
  markerStyleOptions.isVisible = true

  consumerMapStyleCoordinator.setMarkerStyleOptions(markerStyleOptions, markerType: .tripPickupPoint)
}

Objective-C

/** MapViewController.m */

/** Updates the ETA every minute by creating an NSTimer that repeats every minute. */
- (void)schedulePickupMarkerStyleUpdates {
  [NSTimer scheduledTimerWithTimeInterval:60.0 // Update marker ETA every minute.
                                   target:self
                                 selector:@selector(updatePickupMarkerETA)
                                 userInfo:nil
                                  repeats:YES];
}

/** Updates the marker options for GMTCCustomizableMarkerTypeTripPickupPoint for the current time. */
- (void)updatePickupMarkerETA {
  GMTCConsumerMapStyleCoordinator *consumerMapStyleCoordinator = [_mapView consumerMapStyleCoordinator];
  GMTCMarkerStyleOptions *previousOptions = [consumerMapStyleCoordinator markerStyleOptionsForType:GMTCCustomizableMarkerTypeTripPickupPoint];

  // Get updated ETA icon.
  UIImage *updatedETAIcon = [self pickupIconForCurrentTime];

  GMTCMutableMarkerStyleOptions *markerStyleOptions =
                               [[GMTCMutableMarkerStyleOptions alloc] init];
  markerStyleOptions.groundAnchor = kGMSMarkerDefaultGroundAnchor;
  markerStyleOptions.icon = updatedETAIcon;
  markerStyleOptions.zIndex = 100;
  markerStyleOptions.isFlat = NO;
  markerStyleOptions.isVisible = YES;

  [consumerMapStyleCoordinator setMarkerStyleOptions:markerStyleOptions markerType:GMTCCustomizableMarkerTypeTripPickupPoint];
}

קווים פוליגוניים מותאמים אישית

התאמה אישית של Polyline מוגדרת באמצעות GMTCConsumerMapStyleCoordinator#setPolylineStyleOptions(_:polylineType:).

הדוגמה הבאה מציגה איך להגדיר אפשרויות סגנון של קו פוליגוני:

Swift

/** ViewController.swift */

private func changePolylineStyleOptions(
  polylineStyleOptions: GMTCPolylineStyleOptions?,
  polylineType: GMTCPolylineType
) {
  let styleCoordinator = mapView.consumerMapStyleCoordinator
  styleCoordinator.setPolylineStyleOptions(polylineStyleOptions, polylineType: polylineType)
}

/* Setting custom polyline options will override the default values provided by the Consumer SDK.
The default values can be restored by calling setPolylineStyleOptions(_:polylineType:) with nil for the GMTCPolylineStyleOptions.
The active GMTCPolylineStyleOptions can be retrieved via */

private func retrievePolylineStyleOptions(for polylineType: GMTCPolylineType) {
  let styleCoordinator = mapView.consumerMapStyleCoordinator

  // The 'polylineStyleOptions' contains the stored style options for this polyline type.
  let polylineStyleOptions = styleCoordinator.polylineStyleOptions(for: polylineType)
}

Objective-C

/** ViewController.h */

- (void)changePolylineStyleOptions:(nullable GMTCPolylineStyleOptions *)polylineStyleOptions
                      polylineType:(GMTCPolylineType)polylineType {
  GMTCConsumerMapStyleCoordinator *styleCoordinator = _mapView.consumerMapStyleCoordinator;
  [styleCoordinator setPolylineStyleOptions:polylineStyleOptions polylineType:polylineType];
}

/* Setting custom polyline options will override the default values provided by the Consumer SDK.
The default values can be restored by calling setPolylineStyleOptions:polylineType: with nil for the GMTCPolylineStyleOptions.
The active GMTCPolylineStyleOptions can be retrieved via */

- (void)retrievePolylineStyleOptionsForType:(GMTCPolylineType)polylineType {
  GMTCConsumerMapStyleCoordinator *styleCoordinator = _mapView.consumerMapStyleCoordinator;

  // The 'polylineStyleOptions' contains the stored style options for this polyline type.
  GMTCPolylineStyleOptions *polylineStyleOptions = [styleCoordinator polylineStyleOptionsForType:polylineType];
}

סוגי קווים פוליגוניים

אלה סוגי הקווים הזמינים להתאמה אישית:

  • GMTCPolylineType.activeRoute
  • GMTCPolylineType.remainingRoute

GMTCPolylineType.activeRoute ו-GMTCPolylineType.remainingRoute מוצגים לאורך ההתקדמות של הנסיעה וההזמנה. GMTCPolylineType.activeRoute הוא המסלול שהרכב נוסע לנקודה הבאה של הנוסע, למשל האיסוף או ההורדה. GMTCPolylineType.remainingRoute הוא הקטע בנסיעה שנשאר אחרי שהרכב מסיים את GMTCPolylineType.activeRoute.

מאפייני קו פוליגוני

המאפיינים הניתנים להתאמה אישית לכל קו פוליגוני הם קבוצת משנה של המאפיינים שסופקו במפות Google PolylineOptions. ה-SDK של הצרכן GMTCPolylineStyleOptions נוצרות באמצעות אתחול. הם יכולים להיות בלתי ניתנים לשינוי או ניתנים לשינוי אם רוצים לספק ערכים מותאמים אישית לנכס כלשהו. ערכי ברירת מחדל מוגדרים לכל נכס.

המאפיינים הבאים זמינים להתאמה אישית:

  • color
  • width
  • isVisible
  • isTrafficEnabled

אם מגדירים את isVisible לערך false, משביתים את הקו הפוליגוני. ערך ברירת המחדל של isTrafficEnabled הוא false.

דוגמה

Swift

/** MapViewController.swift */

private func updatePolylineUIOptions() {
  // Get the GMTCConsumerMapStyleCoordinator
  let consumerMapStyleCoordinator = mapView.consumerMapStyleCoordinator

  // The polyline type that you would like to set custom UI options for.
  let customizablePolylineType = GMTCPolylineType.activeRoute

  // Initializing polyline options with default values (immutable version).
  let polylineStyleOptions = GMTCPolylineStyleOptions()
  consumerMapStyleCoordinator.setPolylineStyleOptions(
    polylineStyleOptions, polylineType: customizablePolylineType)

  // Initializing polyline options with custom values (mutable version).
  let mutablePolylineStyleOptions = GMTCMutablePolylineStyleOptions()
  mutablePolylineStyleOptions.isVisible = true
  mutablePolylineStyleOptions.isTrafficEnabled = true
  mutablePolylineStyleOptions.setTrafficColorFor(.slow, color: .yellow)
  mutablePolylineStyleOptions.setTrafficColorFor(.trafficJam, color: .purple)
  consumerMapStyleCoordinator.setPolylineStyleOptions(
    mutablePolylineStyleOptions, polylineType: customizablePolylineType)

  // Reset polyline options to default values.
  consumerMapStyleCoordinator.setPolylineStyleOptions(
    nil, polylineType: customizablePolylineType)
}

Objective-C

/** MapViewController.m */

- (void)updatePolylineUIOptions {
  // Get the GMTCConsumerMapStyleCoordinator
  GMTCConsumerMapStyleCoordinator *consumerMapStyleCoordinator = [_mapView consumerMapStyleCoordinator];

  // The polyline type that you would like to set custom UI options for.
  GMTCPolylineType customizablePolylineType = GMTCPolylineTypeActiveRoute;

  // Initializing polyline options with default values (immutable version).
  GMTCPolylineStyleOptions *polylineStyleOptions = [[GMTCPolylineStyleOptions alloc] init];
  [consumerMapStyleCoordinator setPolylineStyleOptions:polylineStyleOptions
                                          polylineType:customizablePolylineType];

  // Initializing polyline options with custom values (mutable version).
  GMTCMutablePolylineStyleOptions *mutablePolylineStyleOptions = [[GMTCMutablePolylineStyleOptions alloc] init];
  mutablePolylineStyleOptions.isVisible = YES;
  mutablePolylineStyleOptions.isTrafficEnabled = YES;
  [mutablePolylineStyleOptions setTrafficColorForSpeed:GMTSSpeedTypeSlow color:[UIColor yellowColor]];
  [mutablePolylineStyleOptions setTrafficColorForSpeed:GMTSSpeedTypeTrafficJam color:[UIColor purpleColor]];
  [consumerMapStyleCoordinator setPolylineStyleOptions:mutablePolylineStyleOptions
                                          polylineType:customizablePolylineType];

  // Reset polyline options to default values.
  [consumerMapStyleCoordinator setPolylineStyleOptions:nil
                                          polylineType:customizablePolylineType];
}

קווים פוליגוניים המודעים לתנועה

כברירת מחדל, שכבת התנועה של הקו הפוליגוני מושבתת. כשהיא מופעלת באמצעות polylineStyleOptions.isTrafficEnabled = true, קטעים שמייצגים קטעים של תנועה לא רגילה משורטטים כמסלול.

מצב התנועה מיוצג באחת מארבע מהירויות: GMTSSpeedType.noData, GMTSSpeedType.normal, GMTSSpeedType.slow ו-GMTSSpeedType.trafficJam. אפשר להתאים אישית את הצבע של כל אחד מסיווגי המהירות האלה באמצעות setTrafficColorFor(_:color:).