iOS Kullanıcı Arayüzü Özelleştirme

Tüketici SDK'sını kullanarak özel işaretçiler uygulayabilir ve çoklu çizgileri uygulama tasarımınıza dönüştürün. Bu tasarım öğeleri, tüketicilerin uygulamasını kullanarak rotanın dinamik önizlemesini görüntüleyin.

Bu kılavuzda, SDK'nın consumerMapStyleCoordinator mülk. Bu özelliğe GMTCMapView sınıfı. Yalnızca kullanıcı arayüzü öğelerini kapsar ve çalışan bir tüketici uygulamasıdır. Arka ucu ayarlama hakkında bilgi için hakkında daha fazla bilgi edinmek için Fleet Engine'i Kullanmaya Başlama.

Kullanıcı arayüzü özelleştirme seçenekleri başlatılıyor

Kullanıcı arayüzü özelleştirme seçeneklerini başlangıçta ayarlamak için kullanılan önerilen geri çağırma GMTCMapViewDelegate'nda beyan edilmiştir. mapViewDidInitialize GMTCMapView nesnesi haritayı oluşturmaya hazır olduğunda geri çağırma tetiklenir. Stil koordinatörü başlatıldı, ancak kullanıcı arayüzü öğesi yok.

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

Özel işaretçiler

Aşağıdaki örnekte, işaretçi stillerini özelleştirmek için GMTCMapView kullanılmaktadır. İşaretçi türünü ve özelliklerini ayarlamak için setMarkerStyleOptions(_:markerType:) Özel işaretçi seçenekleriniz Tüketici SDK'sı tarafından sağlanan varsayılan değerler.

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];
}

İşaretçi türleri

Aşağıdaki işaretçiler özelleştirme için kullanılabilir:

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

Şunu kullan: GMTCCustomizableMarkerType.tripPickupPoint, GMTCCustomizableMarkerType.intermediateDestination ve ve GMTCCustomizableMarkerType.tripDropoffPoint sırasında ara noktaları özelleştirmek Gezi ve Sipariş İlerlemesi.

Araç simgesini özelleştirmek için GMTCCustomizableMarkerType.tripVehicle kullanın görebilirsiniz. İşaretçi simgesi değişmiyor seyahat için gerçek araç türüne göre.

İşaretçi seçenekleri

Her işaretçi için kullanılabilecek özelleştirilebilir özellikler, Google Haritalar tarafından sağlanan tesisler MarkerOptions. Tüketici SDK'sı GMTCMarkerStyleOptions başlatıcı kullanılarak oluşturulur ve oluşturulduktan sonra değiştirilemez. Varsayılan değerler her özellik için belirtildiğinden, yalnızca özel değerlerin belirtilmesi gerekir.

Aşağıdaki özellikler özelleştirme için kullanılabilir:

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

isVisible politikasının yanlış değerine ayarlanması, "kapatılması" ile eşdeğerdir. tıklayın. Bunun yerine kendi kullanıcı arayüzü öğenizi kullanabilmeniz için yeterli miktarda veri sağlanmalıdır.

Örnek

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];
}

Teslim alma işaretçileri için dinamik GMR güncellemeleri

Güncellenen TVS'yi düzenli aralıklarla dinamik olarak gösteren bir teslim alma işaretçisi oluşturmak için: GMTCCustomizableMarkerType.tripPickupPoint için işaretçi stili seçeneklerini güncelleyin.

Örnek

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];
}

Özel çoklu çizgiler

Çoklu çizgi özelleştirmesi, GMTCConsumerMapStyleCoordinator#setPolylineStyleOptions(_:polylineType:)

Aşağıdaki örnekte, çoklu çizgi stil seçeneklerinin nasıl ayarlanacağı gösterilmektedir:

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];
}

Çoklu çizgi türleri

Aşağıdaki çoklu çizgi türleri özelleştirilebilir:

  • GMTCPolylineType.activeRoute
  • GMTCPolylineType.remainingRoute

GMTCPolylineType.activeRoute ve GMTCPolylineType.remainingRoute görüntüleniyor seyahat ve Sipariş İlerlemesi boyunca gösterin. GMTCPolylineType.activeRoute Aracın, yolcunun bir sonraki noktasına gitmek için izlediği rotadır. çok önemli bir parçasıdır. GMTCPolylineType.remainingRoute, segmenttir geriye kalan yolculuk yüzdesi: GMTCPolylineType.activeRoute.

Çoklu çizgi özellikleri

Her bir çoklu çizgi için kullanılabilen özelleştirilebilir özellikler, Google Haritalar'da belirtilen tesisler PolylineOptions. Tüketici SDK'sının GMTCPolylineStyleOptions bir başlatıcı kullanılarak oluşturulur. Bunlar sabit veya değişken olabilir. özelliğini kullanın. Varsayılan değerler her tesis için sağlanır.

Aşağıdaki özellikler özelleştirme için kullanılabilir:

  • color
  • width
  • isVisible
  • isTrafficEnabled

isVisible politikasının false değerine ayarlanması, çoklu çizgiyi devre dışı bırakmaya eşdeğerdir. isTrafficEnabled, varsayılan olarak false değerine ayarlıdır.

Örnek

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];
}

Trafiğe duyarlı çoklu çizgiler

Çoklu çizginin trafik katmanı varsayılan olarak devre dışıdır. Etkinleştirildiğinde polylineStyleOptions.isTrafficEnabled = true ile temsil edilen segmentler normal olmayan trafik uzantıları rota olarak çizilir.

Trafik koşulları dört hızdan biriyle gösterilir: GMTSSpeedType.noData, GMTSSpeedType.normal, GMTSSpeedType.slow ve GMTSSpeedType.trafficJam. Bu hız sınıflandırmalarının her birini temsil eden renk özelleştirilebilir setTrafficColorFor(_:color:) ile birlikte.