उपभोक्ता SDK टूल का इस्तेमाल करके, कस्टम मार्कर लागू किए जा सकते हैं और पॉलीलाइन को आपके ऐप्लिकेशन के डिज़ाइन के मुताबिक रूट करें. ये डिज़ाइन एलिमेंट, आपके ऐप्लिकेशन की मदद से, वाहन के रास्ते की डाइनैमिक झलक दिखा सकते हैं.
इस गाइड में, SDK टूल की मदद से उपलब्ध कराए गए विकल्पों के बारे में बताया गया है
consumerMapStyleCoordinator
प्रॉपर्टी. यह प्रॉपर्टी इनके ज़रिए उपलब्ध है
GMTCMapView
क्लास. इसमें सिर्फ़ यूज़र इंटरफ़ेस (यूआई) एलिमेंट शामिल होते हैं. साथ ही, मान लिया जाता है कि
काम करने वाला कंज़्यूमर ऐप्लिकेशन. बैकएंड सेट अप करने के बारे में जानकारी के लिए
जिन सेवाओं की उपभोक्ता SDK टूल की ज़रूरत होती है उनके बारे में ज़्यादा जानने के लिए,
Fleet Engine के साथ शुरुआत करना.
यूज़र इंटरफ़ेस (यूआई) को पसंद के मुताबिक बनाने के विकल्पों को शुरू किया जा रहा है
सुझाए गए कॉलबैक का इस्तेमाल, यूज़र इंटरफ़ेस (यूआई) को पसंद के मुताबिक बनाने के विकल्पों को सेट करने के लिए किया जाता है
GMTCMapViewDelegate
में बताया गया है. 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 Maps से मिली प्रॉपर्टी
MarkerOptions
.
उपभोक्ता SDK टूल
GMTCMarkerStyleOptions
इन्हें शुरू करने वाले टूल का इस्तेमाल करके बनाया जाता है. साथ ही, इन्हें बनाने के बाद इनमें बदलाव नहीं किया जा सकता. डिफ़ॉल्ट वैल्यू
हर प्रॉपर्टी के लिए अलग-अलग वैल्यू असाइन की जाती हैं, इसलिए सिर्फ़ कस्टम वैल्यू तय करने की ज़रूरत होती है.
इन प्रॉपर्टी को पसंद के मुताबिक बनाया जा सकता है:
groundAnchor
isVisible
iconView
icon
zIndex
isFlat
isVisible
को 'गलत' पर सेट करना, "बंद करने" के बराबर है चिह्नक.
ज़रूरत के मुताबिक डेटा दिया जाना चाहिए, ताकि आप इसकी जगह खुद का यूआई एलिमेंट इस्तेमाल कर सकें.
उदाहरण
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];
}
पिकअप मार्कर के लिए डाइनैमिक ETA अपडेट
समय-समय पर डाइनैमिक तौर पर अपडेट किए गए ETA को दिखाने वाला पिकअप मार्कर बनाने के लिए,
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];
}
कस्टम पॉलीलाइन
पॉलीलाइन कस्टमाइज़ेशन को इसका इस्तेमाल करके सेट किया जाता है
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 Maps पर दी गई प्रॉपर्टी
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:)
के साथ.