रास्ते की पॉलीलाइन पसंद के मुताबिक बनाएं
संग्रह की मदद से व्यवस्थित रहें
अपनी प्राथमिकताओं के आधार पर, कॉन्टेंट को सेव करें और कैटगरी में बांटें.
प्लैटफ़ॉर्म चुनें:
Android
iOS
JavaScript
इस दस्तावेज़ में, उपभोक्ता उपयोगकर्ताओं के लिए वेब पर आधारित जर्नी ट्रैकिंग ऐप्लिकेशन में इस्तेमाल किए जाने वाले मैप के लिए, रास्ते की पॉलीलाइन को पसंद के मुताबिक बनाने का तरीका बताया गया है.
Consumer SDK की मदद से, मैप पर यात्रा के रास्ते के लिए, रूट पॉलीलाइन की स्टाइल तय की जा सकती है या उसकी दिखने की सेटिंग को कंट्रोल किया जा सकता है. एसडीके, यात्रा के चालू या बचे हुए पाथ में मौजूद हर कोऑर्डिनेट की जोड़ी के लिए, एक google.maps.Polyline
ऑब्जेक्ट बनाता है. इसके बाद, लाइब्रेरी इन बदलावों को दो स्थितियों में लागू करती है:
- मैप में ऑब्जेक्ट जोड़ने से पहले
- जब ऑब्जेक्ट के लिए इस्तेमाल किए गए डेटा में बदलाव हुआ हो
रास्ते की पॉलीलाइन की स्टाइल बदलना
मार्कर को स्टाइल करने के तरीके की तरह ही, कस्टम बनाने वाले पैरामीटर का इस्तेमाल करके, रास्ते की पॉलीलाइन को स्टाइल किया जाता है. इसके बाद, स्टाइलिंग को कॉन्फ़िगर करने के लिए, इनमें से किसी एक तरीके का इस्तेमाल करें:
- सबसे आसान तरीका: मैच किए गए सभी
Polyline
ऑब्जेक्ट पर लागू करने के लिए, PolylineOptions
का इस्तेमाल करें. ऐसा तब करें, जब उन्हें बनाया या अपडेट किया गया हो.
- ऐडवांस: कस्टमाइज़ेशन फ़ंक्शन तय करें.
कस्टम बनाने की सुविधाओं की मदद से, Fleet Engine से भेजे गए डेटा के आधार पर ऑब्जेक्ट की स्टाइल को अलग-अलग तरीके से सेट किया जा सकता है. यह फ़ंक्शन, यात्रा की मौजूदा स्थिति के आधार पर हर ऑब्जेक्ट की स्टाइल बदल सकता है. उदाहरण के लिए, जब वाहन धीरे चल रहा हो, तब
Polyline
ऑब्जेक्ट को गहरे रंग का करना या उसे मोटा करना. आपके पास Fleet Engine के बाहर मौजूद सोर्स से भी जुड़ने और उस जानकारी के आधार पर Polyline
ऑब्जेक्ट को स्टाइल करने का विकल्प होता है.
पसंद के मुताबिक बनाने के पैरामीटर
रास्ते की पॉलीलाइन को स्टाइल करते समय, FleetEngineTripLocationProviderOptions
में दिए गए पैरामीटर का इस्तेमाल किया जाता है. ये पैरामीटर, वाहन की यात्रा के दौरान अलग-अलग पाथ की स्थितियां बताते हैं. जैसे:
PolylineOptions
का इस्तेमाल करें
यहां दिए गए उदाहरण में, PolylineOptions
की मदद से Polyline
ऑब्जेक्ट की स्टाइल को कॉन्फ़िगर करने का तरीका बताया गया है. इस पैटर्न का इस्तेमाल करके, पहले बताई गई किसी भी पॉलीलाइन को पसंद के मुताबिक बनाकर, किसी भी Polyline
ऑब्जेक्ट के स्टाइल को पसंद के मुताबिक बनाया जा सकता है.
JavaScript
activePolylineCustomization = {
strokeWidth: 5,
strokeColor: 'black',
};
TypeScript
activePolylineCustomization = {
strokeWidth: 5,
strokeColor: 'black',
};
रास्ते की पॉलीलाइन को स्टाइल करने के लिए, पसंद के मुताबिक बनाने के फ़ंक्शन का इस्तेमाल करना
यहां दिए गए उदाहरण में, चालू रूट की पॉलीलाइन के लिए स्टाइलिंग कॉन्फ़िगर करने का तरीका बताया गया है. इस पैटर्न का इस्तेमाल करके, Polyline
ऑब्जेक्ट की स्टाइल को पसंद के मुताबिक बनाएं. इसके लिए, पहले बताए गए किसी भी रूट पॉलीलाइन कस्टमाइज़ेशन पैरामीटर का इस्तेमाल करें.
JavaScript
// Color the route polyline objects in green if the vehicle is nearby.
activePolylineCustomization =
(params) => {
const distance = params.trip.remainingWaypoints[0].distanceMeters;
if (distance < 1000) {
// params.polylines contains an ordered list of Polyline objects for
// the path.
for (const polylineObject of params.polylines) {
polylineObject.setOptions({strokeColor: 'green'});
}
}
};
TypeScript
// Color the route Polyline objects in green if the vehicle is nearby.
activePolylineCustomization =
(params: TripPolylineCustomizationFunctionParams) => {
const distance = params.trip.remainingWaypoints[0].distanceMeters;
if (distance < 1000) {
// params.polylines contains an ordered list of Polyline objects for
// the path.
for (const polylineObject of params.polylines) {
polylineObject.setOptions({strokeColor: 'green'});
}
}
};
रास्ते की पॉलीलाइन के दिखने की स्थिति को कंट्रोल करना
डिफ़ॉल्ट रूप से, सभी Polyline
ऑब्जेक्ट दिखते हैं. किसी Polyline
ऑब्जेक्ट को अदृश्य बनाने के लिए, उसकी visible
प्रॉपर्टी को इस तरह सेट करें:
JavaScript
remainingPolylineCustomization = {visible: false};
TypeScript
remainingPolylineCustomization = {visible: false};
जब तक कुछ अलग से न बताया जाए, तब तक इस पेज की सामग्री को Creative Commons Attribution 4.0 License के तहत और कोड के नमूनों को Apache 2.0 License के तहत लाइसेंस मिला है. ज़्यादा जानकारी के लिए, Google Developers साइट नीतियां देखें. Oracle और/या इससे जुड़ी हुई कंपनियों का, Java एक रजिस्टर किया हुआ ट्रेडमार्क है.
आखिरी बार 2025-09-05 (UTC) को अपडेट किया गया.
[[["समझने में आसान है","easyToUnderstand","thumb-up"],["मेरी समस्या हल हो गई","solvedMyProblem","thumb-up"],["अन्य","otherUp","thumb-up"]],[["वह जानकारी मौजूद नहीं है जो मुझे चाहिए","missingTheInformationINeed","thumb-down"],["बहुत मुश्किल है / बहुत सारे चरण हैं","tooComplicatedTooManySteps","thumb-down"],["पुराना","outOfDate","thumb-down"],["अनुवाद से जुड़ी समस्या","translationIssue","thumb-down"],["सैंपल / कोड से जुड़ी समस्या","samplesCodeIssue","thumb-down"],["अन्य","otherDown","thumb-down"]],["आखिरी बार 2025-09-05 (UTC) को अपडेट किया गया."],[[["\u003cp\u003eThis documentation explains how to customize the appearance of route polylines within web-based journey tracking applications using the Consumer SDK.\u003c/p\u003e\n"],["\u003cp\u003eYou can customize the style of polylines representing the traveled, active, and remaining portions of a journey's route.\u003c/p\u003e\n"],["\u003cp\u003eStyling can be achieved using simple \u003ccode\u003ePolylineOptions\u003c/code\u003e for uniform styling or with customization functions for dynamic, data-driven styling based on the trip's state.\u003c/p\u003e\n"],["\u003cp\u003eRoute polyline visibility can be controlled by setting the \u003ccode\u003evisible\u003c/code\u003e property to \u003ccode\u003efalse\u003c/code\u003e for the desired polyline customization parameter.\u003c/p\u003e\n"]]],["This document details customizing route polylines in web-based journey tracking apps using the Consumer SDK. You can control the visibility and style of route polylines via `PolylineOptions` for simple styling or through customization functions for more dynamic styling, based on data from Fleet Engine or external sources. Polylines can be customized for \"already traveled,\" \"actively traveled,\" and \"not-yet traveled\" paths using `takenPolylineCustomization`, `activePolylineCustomization`, and `remainingPolylineCustomization` parameters respectively. Visibility can be toggled using the `visible` property.\n"],null,["Select platform: [Android](/maps/documentation/mobility/journey-sharing/on-demand/android/customize-polylines \"View this page for the Android platform docs.\") [iOS](/maps/documentation/mobility/journey-sharing/on-demand/ios/customize-polylines \"View this page for the iOS platform docs.\") [JavaScript](/maps/documentation/mobility/journey-sharing/on-demand/javascript/customize-route-polylines \"View this page for the JavaScript platform docs.\")\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\nThis document covers how to customize route polylines for the map you use in\nyour web-based journey tracking app for consumer users.\n\nWith the Consumer SDK, you can control route polyline visibility or style the\nroute polyline for a journey's route on the map. The SDK creates a\n[`google.maps.Polyline`](/maps/documentation/javascript/reference/polygon#Polyline) object for each pair of coordinates in the journey's\nactive or remaining path. The library then applies these customizations in\ntwo situations:\n\n- before adding the objects to the map\n- when the data used for the objects have changed\n\nStyle route polylines\n\nSimilar to how you can style markers, you style route polylines using\n**customization parameters**. From there, you configure styling using one of the\nfollowing approaches:\n\n- **Simplest** : Use `PolylineOptions` to apply to all of the matched `Polyline` objects when they are created or updated.\n- **Advanced** : Specify a **customization function** . Customization functions allow for individual styling of the objects based on data sent by Fleet Engine. The function can change the styling of each object based on the current state of the journey; for example, coloring the `Polyline` object a deeper shade, or making it thicker when the vehicle is moving slower. You can even join against from sources outside Fleet Engine and style the `Polyline` object based on that information.\n\nCustomization parameters\n\nWhen styling route polylines, you use parameters provided in\n[`FleetEngineTripLocationProviderOptions`](/maps/documentation/javascript/reference/journey-sharing-trip-and-order-progress#FleetEngineTripLocationProviderOptions). These parameters provide for\ndifferent path states in the vehicle's journey, as follows:\n\n- **Already traveled** paths: Use [`takenPolylineCustomization`](/maps/documentation/javascript/reference/journey-sharing-trip-and-order-progress#FleetEngineTripLocationProviderOptions.takenPolylineCustomization).\n- **Actively traveled** path: Use [`activePolylineCustomization`](/maps/documentation/javascript/reference/journey-sharing-trip-and-order-progress#FleetEngineTripLocationProviderOptions.activePolylineCustomization).\n- **Not-yet traveled** path: Use [`remainingPolylineCustomization`](/maps/documentation/javascript/reference/journey-sharing-trip-and-order-progress#FleetEngineTripLocationProviderOptions.remainingPolylineCustomization).\n\nUse `PolylineOptions`\n\nThe following example shows how to configure the styling for a `Polyline` object\nwith [`PolylineOptions`](/maps/documentation/javascript/reference/polygon#PolylineOptions). Follow this pattern to customize the styling of\nany `Polyline` object using any of the polyline customizations listed earlier.\n\n\u003cbr /\u003e\n\nJavaScript\n\n\u003cbr /\u003e\n\n activePolylineCustomization = {\n strokeWidth: 5,\n strokeColor: 'black',\n };\n\n\u003cbr /\u003e\n\nTypeScript\n\n\u003cbr /\u003e\n\n activePolylineCustomization = {\n strokeWidth: 5,\n strokeColor: 'black',\n };\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\nUse customization functions to style route polylines\n\nThe following example shows how to configure styling for an active route\npolyline. Follow this pattern to customize the styling of any `Polyline` object\nusing any of the route polyline customization parameters listed earlier.\n\n\u003cbr /\u003e\n\nJavaScript\n\n\u003cbr /\u003e\n\n // Color the route polyline objects in green if the vehicle is nearby.\n activePolylineCustomization =\n (params) =\u003e {\n const distance = params.trip.remainingWaypoints[0].distanceMeters;\n if (distance \u003c 1000) {\n\n // params.polylines contains an ordered list of Polyline objects for\n // the path.\n for (const polylineObject of params.polylines) {\n polylineObject.setOptions({strokeColor: 'green'});\n }\n }\n };\n\n\u003cbr /\u003e\n\nTypeScript\n\n\u003cbr /\u003e\n\n // Color the route Polyline objects in green if the vehicle is nearby.\n activePolylineCustomization =\n (params: TripPolylineCustomizationFunctionParams) =\u003e {\n const distance = params.trip.remainingWaypoints[0].distanceMeters;\n if (distance \u003c 1000) {\n\n // params.polylines contains an ordered list of Polyline objects for\n // the path.\n for (const polylineObject of params.polylines) {\n polylineObject.setOptions({strokeColor: 'green'});\n }\n }\n };\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\nControl route polyline visibility\n\nBy default, all `Polyline` objects are visible. To make a `Polyline` object\ninvisible, set its [`visible`](/maps/documentation/javascript/reference/polygon#PolylineOptions) property:\n\n\u003cbr /\u003e\n\nJavaScript\n\n\u003cbr /\u003e\n\n remainingPolylineCustomization = {visible: false};\n\n\u003cbr /\u003e\n\nTypeScript\n\n\u003cbr /\u003e\n\n remainingPolylineCustomization = {visible: false};\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e"]]