Tüketici SDK'sını kullanarak özel işaretçiler uygulayabilir ve çoklu çizgileri uygulama tasarımınıza yönlendirebilirsiniz. Bu tasarım öğeleri, Tüketici uygulamanızın araç rotasının dinamik önizlemesini görüntülemesini sağlar.
Bu kılavuzda SDK'nın consumerMapStyleCoordinator
özelliğinde sunduğu seçenekler açıklanmaktadır. Bu özellik GMTCMapView
sınıfı aracılığıyla kullanılabilir. Yalnızca kullanıcı arayüzü öğelerini kapsar ve çalışan bir Tüketici uygulamanızın olduğu varsayılır. Tüketici SDK'sının ihtiyaç duyduğu arka uç hizmetlerini ayarlama hakkında bilgi edinmek için Fleet Engine'i Kullanmaya Başlama bölümüne bakın.
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
özelliğinde belirtilir. GMTCMapView
nesnesi harita oluşturulmaya hazır olduğunda mapViewDidInitialize
geri çağırması tetiklenir.
Stil koordinatörü başlatıldı ancak hiçbir 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ılmıştır.
İşaretçi türünü ve özelliklerini ayarlamak için setMarkerStyleOptions(_:markerType:)
işlevini kullanın. Özel işaretçi seçenekleriniz, Consumer SDK tarafından sağlanan varsayılan değerleri geçersiz kılar.
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
Özelleştirme için aşağıdaki işaretçiler kullanılabilir:
GMTCCustomizableMarkerType.unknown
GMTCCustomizableMarkerType.tripPickupPoint
GMTCCustomizableMarkerType.tripDropoffPoint
GMTCCustomizableMarkerType.tripVehicle
GMTCCustomizableMarkerType.intermediateDestination
Gezi ve Sipariş İlerlemesi sırasında ara noktaları özelleştirmek için GMTCCustomizableMarkerType.tripPickupPoint
, GMTCCustomizableMarkerType.intermediateDestination
ve GMTCCustomizableMarkerType.tripDropoffPoint
kullanın.
Yolculuk ve Sipariş İlerleme Durumu sırasında
araç simgesini özelleştirmek için GMTCCustomizableMarkerType.tripVehicle
öğesini kullanın. İşaretçi simgesi, yolculuğun asıl
aracının türüne göre değişmez.
İşaretçi seçenekleri
Her bir işaretçide kullanılabilen özelleştirilebilir özellikler, Google Haritalar MarkerOptions
tarafından sağlanan mülklerin bir alt kümesidir.
Tüketici SDK'sı
GMTCMarkerStyleOptions
bir başlatıcı kullanılarak derlenir ve oluşturulduktan sonra değiştirilemez. Her bir özellik için varsayılan değerler sağlandığı için yalnızca özel değerlerin belirtilmesi gerekir.
Aşağıdaki özellikler özelleştirme için kullanılabilir:
groundAnchor
isVisible
iconView
icon
zIndex
isFlat
isVisible
öğesinin yanlış değerine ayarlanması, işaretçiyi "kapatma"yla eşdeğerdir.
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 TVS güncellemeleri
Güncellenen TVS'yi düzenli olarak dinamik bir şekilde gösteren bir teslim alma işaretçisi oluşturmak için GMTCCustomizableMarkerType.tripPickupPoint
için işaretçi stil 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ştirme GMTCConsumerMapStyleCoordinator#setPolylineStyleOptions(_:polylineType:)
kullanılarak ayarlanır.
Aşağıdaki örnekte, çoklu çizgi stili 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
Özelleştirme için aşağıdaki çoklu çizgi türleri kullanılabilir:
GMTCPolylineType.activeRoute
GMTCPolylineType.remainingRoute
Yolculuk ve Sipariş İlerleme Durumu
boyunca GMTCPolylineType.activeRoute
ve GMTCPolylineType.remainingRoute
görüntüleniyor. GMTCPolylineType.activeRoute
, aracın ister alma ister indirme olsun, sürücünün bir sonraki noktasına gitmek için gittiği rotadır. GMTCPolylineType.remainingRoute
, araç GMTCPolylineType.activeRoute
tamamlandıktan sonra kalan seyahat segmentidir.
Çoklu çizgi özellikleri
Her bir çoklu çizgi için kullanılabilen özelleştirilebilir özellikler, Google Haritalar PolylineOptions
özelliğinde sunulan mülklerin bir alt kümesidir.
Tüketici SDK'ları GMTCPolylineStyleOptions
bir başlatıcı kullanılarak derlenir. Herhangi bir özellik için özel değerler sağlamak istiyorsanız bunlar sabit veya değişken olabilir. Her bir özellik için varsayılan değerler sağlanır.
Aşağıdaki özellikler özelleştirme için kullanılabilir:
color
width
isVisible
isTrafficEnabled
isVisible
politikasını false
değerine ayarlamak, çoklu çizgiyi devre dışı bırakmaya eş değerdir.
Varsayılan olarak isTrafficEnabled
, false
değerine ayarlanmıştı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. polylineStyleOptions.isTrafficEnabled = true
ile etkinleştirildiğinde, normal olmayan trafik alanlarını temsil eden segmentler rota olarak çizilir.
Trafik koşulları şu 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 setTrafficColorFor(_:color:)
ile özelleştirilebilir.