התאמה אישית של קווים פוליגוניים של נתיב
קל לארגן דפים בעזרת אוספים
אפשר לשמור ולסווג תוכן על סמך ההעדפות שלך.
כדי להתאים אישית את קווי המסלול, משתמשים בשיטה ConsumerMapStyle.setPolylineStyleOptions
. אם מגדירים אפשרויות מותאמות אישית של קו פוליגון, הן מבטלות את ערכי ברירת המחדל שמוגדרים ב-Consumer SDK.
כדי לשחזר את ערכי ברירת המחדל, קוראים ל-setPolylineStyleOptions
עם null
לפרמטר PolylineOptions
.
כדי לאחזר את PolylineOptions
הפעיל, משתמשים בשיטה getPolylineStyleOptions
.
מידע נוסף זמין במאמר ConsumerMapStyle.setPolylineStyleOptions
.
סוגים של קווי פוליגון של מסלולים
אפשר להתאים אישית את סוגי הקווים המקוקווים של המסלול הבאים:
ACTIVE_ROUTE
REMAINING_ROUTE
הסמלים ACTIVE_ROUTE
ו-REMAINING_ROUTE
מוצגים במהלך מעקב אחרי נסיעה ומייצגים את המסלול של הרכב.
מאפיינים של קו מרובה של מסלול
במפות Google יש מאפיינים שאפשר להתאים אישית, שזמינים לכל קו פוליגוני ב-PolylineOptions
.
כדי ליצור את PolylineOptions
, משתמשים בבונה שלו.
כדי לציין מאפיינים מותאמים אישית, משתמשים בשיטות בסגנון Setter. מכיוון שהשיטה מספקת ערכי ברירת מחדל לכל נכס, צריך לציין רק ערכים מותאמים אישית.
כדי להשבית את הקו המקוטע, מגדירים את visible
לערך false
.
פרטים נוספים זמינים במאמר בנושא PolylineOptions
בתיעוד למפתחי Android.
דוגמה
Java
// Initializing polyline style options.
consumerController
.getConsumerMapStyle()
.addOnSuccessListener(
consumerMapStyle -> {
consumerMapStyle.setPolylineStyleOptions(
PolylineType.ACTIVE_ROUTE,
new PolylineOptions()
.visible(false));
});
// Reset polyline options to default values.
consumerMapStyle.setPolylineStyleOptions(PolylineType.ACTIVE_ROUTE, null);
Kotlin
// Initializing polyline options.
consumerController
.getConsumerMapStyle()
.addOnSuccessListener({ consumerMapStyle ->
consumerMapStyle.setPolylineStyleOptions(
PolylineType.ACTIVE_ROUTE,
PolylineOptions().visible(false)
)
})
// Reset polyline options to default values.
consumerMapStyle.setPolylineStyleOptions(PolylineType.ACTIVE_ROUTE, null)
המסלול הפעיל והמסלול שנותר
אם שיתוף המסלול מופעל, האפליקציה יכולה להתאים אישית את חוויית המשתמש באמצעות קווים שבורים כדי להציג את המסלול הפעיל והמסלול שנותר לרכב.
המסלול הפעיל הוא הנתיב שבו הרכב נוסע כרגע כדי להגיע לנקודת הדרך הבאה בנסיעה הפעילה של הלקוח.
המסלול שנותר הוא הנתיב שהרכב צריך לעבור אחרי המסלול הפעיל. אם נקודת הדרך הפעילה במסלול היא נקודת הדרך האחרונה בנסיעה,
המסלול שנותר לא קיים.
אתם יכולים להתאים אישית את הקווים הפוליגוניים הפעילים והנותרים באפליקציה שלכם ולשלוט בנראות שלהם. כברירת מחדל, המסלול הפעיל גלוי והמסלול הנותר לא גלוי.
דוגמה
Java
// Initializing polyline options.
consumerController
.getConsumerMapStyle()
.addOnSuccessListener(
consumerMapStyle -> {
consumerMapStyle.setPolylineStyleOptions(
PolylineType.ACTIVE_ROUTE,
new PolylineOptions()
.color(Color.BLUE));
consumerMapStyle.setPolylineStyleOptions(
PolylineType.REMAINING_ROUTE,
new PolylineOptions()
.color(Color.BLACK)
.width(5)
.visible(true));
});
// Reset polyline options to default values.
consumerMapStyle.setPolylineStyleOptions(PolylineType.ACTIVE_ROUTE, null);
consumerMapStyle.setPolylineStyleOptions(PolylineType.REMAINING_ROUTE, null);
Kotlin
// Initializing polyline options.
consumerController
.getConsumerMapStyle()
.addOnSuccessListener({ consumerMapStyle ->
{
consumerMapStyle.setPolylineStyleOptions(
PolylineType.ACTIVE_ROUTE,
PolylineOptions().color(Color.BLUE)
)
consumerMapStyle.setPolylineStyleOptions(
PolylineType.REMAINING_ROUTE,
PolylineOptions().color(Color.BLACK).width(5).visible(true)
)
}
})
// Reset polyline options to default values.
consumerMapStyle.setPolylineStyleOptions(PolylineType.ACTIVE_ROUTE, null)
consumerMapStyle.setPolylineStyleOptions(PolylineType.REMAINING_ROUTE, null)
קווי פוליגון עם נתונים על תנועת כלי רכב
שכבת התנועה של הקו המרובה מושבתת כברירת מחדל. כשמפעילים את ההגדרה הזו, רכיב ה-renderer מצייר מקטעים מעל קו המסלול שמייצגים אזורים עם תנועה לא רגילה. הוא כולל קיזוז בהתאם לתנאי התנועה.
מידע נוסף זמין במסמכי התיעוד למפתחים של Android בנושא Polyline.
מפות Google מייצגות את מצב התנועה באחד מארבעה סוגי מהירות.
אפשר להתאים אישית את הצבע של כל סוג מהירות.
כדי להפעיל קווים עקומים שמשתנים בהתאם לתנועת התנועה, יוצרים אובייקט TrafficStyle
ואז מעבירים אותו אל ConsumerMapStyle
על ידי קריאה ל-setPolylineTrafficStyle()
.
דוגמה
Java
// TrafficStyle is part of the Consumer SDK.
int orange = Color.rgb(255, 165, 0);
TrafficStyle trafficStyle = TrafficStyle.builder()
.setTrafficVisibility(true)
.setTrafficColor(SpeedType.NO_DATA, Color.GREY)
.setTrafficColor(SpeedType.NORMAL, Color.BLUE)
.setTrafficColor(SpeedType.SLOW, orange)
.setTrafficColor(SpeedType.TRAFFIC_JAM, Color.RED)
.build();
consumerMapStyle.setPolylineTrafficStyle(PolylineType.ACTIVE_ROUTE, trafficStyle);
Kotlin
// TrafficStyle is part of the Consumer SDK.
val orange = Color.rgb(255, 165, 0)
val trafficStyle =
TrafficStyle.builder()
.setTrafficVisibility(true)
.setTrafficColor(SpeedType.NO_DATA, Color.GRAY)
.setTrafficColor(SpeedType.NORMAL, Color.BLUE)
.setTrafficColor(SpeedType.SLOW, orange)
.setTrafficColor(SpeedType.TRAFFIC_JAM, Color.RED)
.build()
consumerMapStyle.setPolylineTrafficStyle(PolylineType.ACTIVE_ROUTE, trafficStyle)
אלא אם צוין אחרת, התוכן של דף זה הוא ברישיון Creative Commons Attribution 4.0 ודוגמאות הקוד הן ברישיון Apache 2.0. לפרטים, ניתן לעיין במדיניות האתר Google Developers. Java הוא סימן מסחרי רשום של חברת Oracle ו/או של השותפים העצמאיים שלה.
עדכון אחרון: 2025-09-04 (שעון 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-04 (שעון UTC)."],[[["\u003cp\u003eCustomize the appearance of route polylines (active, remaining) using \u003ccode\u003eConsumerMapStyle.setPolylineStyleOptions\u003c/code\u003e to override default settings.\u003c/p\u003e\n"],["\u003cp\u003eRestore default polyline styles by calling \u003ccode\u003esetPolylineStyleOptions\u003c/code\u003e with \u003ccode\u003enull\u003c/code\u003e for the \u003ccode\u003ePolylineOptions\u003c/code\u003e parameter.\u003c/p\u003e\n"],["\u003cp\u003eControl the visibility and styling of active and remaining route polylines to enhance the user's trip visualization.\u003c/p\u003e\n"],["\u003cp\u003eEnable and customize traffic-aware polylines with \u003ccode\u003eTrafficStyle\u003c/code\u003e to visually represent traffic conditions along the route.\u003c/p\u003e\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\nYou customize route polylines using the\n`ConsumerMapStyle.setPolylineStyleOptions` method. If you set custom polyline\noptions, they override the default values provided by the Consumer SDK.\n\n**To restore the default values** , call\n[`setPolylineStyleOptions`](/maps/documentation/mobility/journey-sharing/on-demand/reference/consumer_2/android/reference/com/google/android/libraries/mapsplatform/transportation/consumer/view/ConsumerMapStyle#setPolylineStyleOptions(int,%20com.google.android.gms.maps.model.PolylineOptions))\nwith `null` for the `PolylineOptions` parameter.\n\n**To retrieve the active `PolylineOptions`** , use\n[`getPolylineStyleOptions`](/maps/documentation/mobility/journey-sharing/on-demand/reference/consumer_2/android/reference/com/google/android/libraries/mapsplatform/transportation/consumer/view/ConsumerMapStyle#getPolylineStyleOptions(int)) method.\n\nFor more information, see\n[`ConsumerMapStyle.setPolylineStyleOptions`](/maps/documentation/mobility/journey-sharing/on-demand/reference/consumer_2/android/reference/com/google/android/libraries/mapsplatform/transportation/consumer/view/ConsumerMapStyle#setPolylineStyleOptions(int,%20com.google.android.gms.maps.model.PolylineOptions)).\n\nRoute polyline types\n\nYou can customize the following route polyline types:\n\n- `ACTIVE_ROUTE`\n- `REMAINING_ROUTE`\n\n`ACTIVE_ROUTE` and `REMAINING_ROUTE` are displayed while following a trip and\nrepresent the [vehicle's route](#active-route).\n\nRoute polyline properties\n\nGoogle Maps provides customizable properties available for each polyline in\n`PolylineOptions`.\n\n- **To build `PolylineOptions`**, use its constructor.\n\n- **To specify customized properties**, use 'Setter' style methods. Since\n the method provides default values for each property, you only need\n to specify any custom values.\n\n- **To turn off the polyline** , set `visible` to `false`.\n\nFor more details, see\n[`PolylineOptions`](https://developers.google.com/android/reference/com/google/android/gms/maps/model/PolylineOptions) in the Android developer documentation.\n\nExample \n\nJava \n\n // Initializing polyline style options.\n consumerController\n .getConsumerMapStyle()\n .addOnSuccessListener(\n consumerMapStyle -\u003e {\n consumerMapStyle.setPolylineStyleOptions(\n PolylineType.ACTIVE_ROUTE,\n new PolylineOptions()\n .visible(false));\n });\n\n // Reset polyline options to default values.\n consumerMapStyle.setPolylineStyleOptions(PolylineType.ACTIVE_ROUTE, null);\n\nKotlin \n\n // Initializing polyline options.\n consumerController\n .getConsumerMapStyle()\n .addOnSuccessListener({ consumerMapStyle -\u003e\n consumerMapStyle.setPolylineStyleOptions(\n PolylineType.ACTIVE_ROUTE,\n PolylineOptions().visible(false)\n )\n })\n\n // Reset polyline options to default values.\n consumerMapStyle.setPolylineStyleOptions(PolylineType.ACTIVE_ROUTE, null)\n\nActive and Remaining Route\n\nWith journey sharing enabled, your app can customize the\nuser's experience using polylines to show the active and remaining\nroute for your vehicle.\n\n- The *active route* is the path the vehicle is now traveling to reach\n the next waypoint in the consumer's active trip.\n\n- The *remaining route* is the path the vehicle still has to travel past\n the active route. When the active route waypoint is the last trip waypoint,\n the remaining route does not exist.\n\nYou can customize and control visibility of active and remaining polylines in\nyour app. By default, the active route is visible and the remaining route\nis not visible.\n\nExample \n\nJava \n\n // Initializing polyline options.\n consumerController\n .getConsumerMapStyle()\n .addOnSuccessListener(\n consumerMapStyle -\u003e {\n consumerMapStyle.setPolylineStyleOptions(\n PolylineType.ACTIVE_ROUTE,\n new PolylineOptions()\n .color(Color.BLUE));\n consumerMapStyle.setPolylineStyleOptions(\n PolylineType.REMAINING_ROUTE,\n new PolylineOptions()\n .color(Color.BLACK)\n .width(5)\n .visible(true));\n });\n\n // Reset polyline options to default values.\n consumerMapStyle.setPolylineStyleOptions(PolylineType.ACTIVE_ROUTE, null);\n consumerMapStyle.setPolylineStyleOptions(PolylineType.REMAINING_ROUTE, null);\n\nKotlin \n\n // Initializing polyline options.\n consumerController\n .getConsumerMapStyle()\n .addOnSuccessListener({ consumerMapStyle -\u003e\n {\n consumerMapStyle.setPolylineStyleOptions(\n PolylineType.ACTIVE_ROUTE,\n PolylineOptions().color(Color.BLUE)\n )\n\n consumerMapStyle.setPolylineStyleOptions(\n PolylineType.REMAINING_ROUTE,\n PolylineOptions().color(Color.BLACK).width(5).visible(true)\n )\n }\n })\n\n // Reset polyline options to default values.\n consumerMapStyle.setPolylineStyleOptions(PolylineType.ACTIVE_ROUTE, null)\n\n consumerMapStyle.setPolylineStyleOptions(PolylineType.REMAINING_ROUTE, null)\n\nTraffic-aware polylines\n\nThe traffic layer of the polyline is disabled by default. When you enable it,\nthe renderer draws segments above the route polyline that represent stretches of\nnon-normal traffic. It includes an offset depending on the traffic condition.\nSee the Android Developer documentation for [Polyline](https://developers.google.com/android/reference/com/google/android/gms/maps/model/Polyline#public-void-setzindex-float-zindex) for more information.\n\nGoogle maps represent traffic conditions as one of\n[four speed types](/maps/documentation/mobility/journey-sharing/on-demand/reference/consumer_2/android/reference/com/google/android/libraries/mapsplatform/transportation/consumer/model/TrafficData.SpeedReadingInterval.SpeedType).\nYou can customize the color for each speed type.\n\n**To enable traffic-aware polylines** , construct a `TrafficStyle` object\nand then pass it to `ConsumerMapStyle` by calling `setPolylineTrafficStyle()`.\n\nExample \n\nJava \n\n // TrafficStyle is part of the Consumer SDK.\n int orange = Color.rgb(255, 165, 0);\n TrafficStyle trafficStyle = TrafficStyle.builder()\n .setTrafficVisibility(true)\n .setTrafficColor(SpeedType.NO_DATA, Color.GREY)\n .setTrafficColor(SpeedType.NORMAL, Color.BLUE)\n .setTrafficColor(SpeedType.SLOW, orange)\n .setTrafficColor(SpeedType.TRAFFIC_JAM, Color.RED)\n .build();\n\n consumerMapStyle.setPolylineTrafficStyle(PolylineType.ACTIVE_ROUTE, trafficStyle);\n\nKotlin \n\n // TrafficStyle is part of the Consumer SDK.\n val orange = Color.rgb(255, 165, 0)\n val trafficStyle =\n TrafficStyle.builder()\n .setTrafficVisibility(true)\n .setTrafficColor(SpeedType.NO_DATA, Color.GRAY)\n .setTrafficColor(SpeedType.NORMAL, Color.BLUE)\n .setTrafficColor(SpeedType.SLOW, orange)\n .setTrafficColor(SpeedType.TRAFFIC_JAM, Color.RED)\n .build()\n\n consumerMapStyle.setPolylineTrafficStyle(PolylineType.ACTIVE_ROUTE, trafficStyle)"]]