मार्कर कस्टमाइज़ करें

प्लैटफ़ॉर्म चुनें: Android iOS JavaScript

मार्कर (या पॉलीलाइन) कस्टमाइज़ करने से पहले, आपको यूज़र इंटरफ़ेस (यूआई) को पसंद के मुताबिक बनाने के विकल्प.

यूज़र इंटरफ़ेस (यूआई) को पसंद के मुताबिक बनाने के विकल्पों को शुरू करें

सुझाए गए कॉलबैक का इस्तेमाल, यूज़र इंटरफ़ेस (यूआई) को पसंद के मुताबिक बनाने के विकल्पों को सेट करने के लिए किया जाता है 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

/** MapViewController.swift */

func updateMarkerUIOptions() {
  let customizableMarkerType = GMTCCustomizableMarkerType.tripVehicle
  let markerStyleOptions = GMTCMutableMarkerStyleOptions()
  markerStyleOptions.groundAnchor = groundAnchor
  markerStyleOptions.isVisible = true
  markerStyleOptions.icon = icon
  markerStyleOptions.zIndex = 100
  markerStyleOptions.isFlat = false
  let coordinator = self.mapView.consumerMapStyleCoordinator
  coordinator.setMarkerStyleOptions(markerStyleOptions, markerType: customizableMarkerType)
}

/** 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


/** MapViewController.m */

- (void)updateMarkerUIOptions {
  // The marker type that you would like to set custom UI options for.
  GMTCCustomizableMarkerType customizableMarkerType = GMTCCustomizableMarkerTypeTripVehicle;

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

  [[_mapView consumerMapStyleCoordinator] setMarkerStyleOptions:markerStyleOptions markerType:customizableMarkerType];
}

/** 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: मार्कर बंद करने के लिए, isVisible को गलत पर सेट करें. काफ़ी डेटा दिया जाना चाहिए, ताकि आप इसकी जगह पर अपने खुद के यूज़र इंटरफ़ेस (यूआई) एलिमेंट का इस्तेमाल कर सकें.
  • iconView
  • icon
  • zIndex
  • isFlat

उदाहरण

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

आगे क्या करना है