उपभोक्ता SDK टूल का इस्तेमाल करके, अपने ऐप्लिकेशन के डिज़ाइन में कस्टम मार्कर और रूट पॉलीलाइन लागू किए जा सकते हैं. डिज़ाइन से जुड़े इन एलिमेंट की मदद से, आपका Consumer ऐप्लिकेशन, वाहन के रास्ते की डाइनैमिक झलक दिखा पाता है.
इस गाइड में उन विकल्पों के बारे में बताया गया है जो 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 को डाइनैमिक तौर पर दिखाने वाला पिकअप मार्कर बनाने के लिए, 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:)
से पसंद के मुताबिक बनाया जा सकता है.