Polylinien für Routen anpassen
Mit Sammlungen den Überblick behalten
Sie können Inhalte basierend auf Ihren Einstellungen speichern und kategorisieren.
Plattform auswählen:
Android
iOS
JavaScript
Sie passen Routenpolylinien mit der Methode ConsumerMapStyle.setPolylineStyleOptions
an. Wenn Sie benutzerdefinierte Polylinienoptionen festlegen, werden die Standardwerte des Consumer SDK überschrieben.
Standardwerte wiederherstellen: Rufen Sie setPolylineStyleOptions
mit null
für den Parameter PolylineOptions
auf.
Verwenden Sie die Methode getPolylineStyleOptions
, um die aktive PolylineOptions
abzurufen.
Weitere Informationen finden Sie unter ConsumerMapStyle.setPolylineStyleOptions
.
Polylinien für Routen
Sie können die folgenden Arten von Routenpolylinien anpassen:
ACTIVE_ROUTE
REMAINING_ROUTE
ACTIVE_ROUTE
und REMAINING_ROUTE
werden angezeigt, wenn Sie einer Fahrt folgen, und stellen die Route des Fahrzeugs dar.
Eigenschaften von Routenpolylinien
Google Maps bietet anpassbare Eigenschaften für jede Polylinie in PolylineOptions
.
Verwenden Sie den Konstruktor, um PolylineOptions
zu erstellen.
Benutzerdefinierte Eigenschaften angeben: Verwenden Sie Methoden im „Setter“-Stil. Da die Methode Standardwerte für jede Eigenschaft bereitstellt, müssen Sie nur benutzerdefinierte Werte angeben.
Wenn Sie die Polylinie deaktivieren möchten, legen Sie visible
auf false
fest.
Weitere Informationen finden Sie in der Android-Entwicklerdokumentation unter PolylineOptions
.
Beispiel
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)
Aktive und verbleibende Route
Wenn die Funktion „Fahrten teilen“ aktiviert ist, kann Ihre App die Nutzererfahrung mithilfe von Polylinien anpassen, um die aktive und die verbleibende Route für Ihr Fahrzeug anzuzeigen.
Die aktive Route ist der Weg, den das Fahrzeug gerade zurücklegt, um den nächsten Wegpunkt der aktiven Fahrt des Nutzers zu erreichen.
Die verbleibende Route ist der Weg, den das Fahrzeug nach der aktiven Route noch zurücklegen muss. Wenn der aktive Routen-Waypoint der letzte Trip-Waypoint ist, ist die verbleibende Route nicht vorhanden.
Sie können die Sichtbarkeit von aktiven und verbleibenden Polylinien in Ihrer App anpassen und steuern. Standardmäßig ist die aktive Route sichtbar und die verbleibende Route nicht.
Beispiel
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)
Polylinien mit Verkehrsdaten
Die Verkehrsebene der Polylinie ist standardmäßig deaktiviert. Wenn Sie diese Option aktivieren, werden Segmente über der Routen-Polylinie gerendert, die Abschnitte mit nicht normalem Verkehrsaufkommen darstellen. Sie enthält einen Offset, der von der Verkehrslage abhängt.
Weitere Informationen finden Sie in der Android-Entwicklerdokumentation unter Polyline.
In Google Maps wird die Verkehrslage als einer von vier Geschwindigkeitstypen dargestellt.
Sie können die Farbe für jeden Geschwindigkeitstyp anpassen.
Wenn Sie verkehrsabhängige Polylinien aktivieren möchten, erstellen Sie ein TrafficStyle
-Objekt und übergeben Sie es dann an ConsumerMapStyle
, indem Sie setPolylineTrafficStyle()
aufrufen.
Beispiel
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)
Sofern nicht anders angegeben, sind die Inhalte dieser Seite unter der Creative Commons Attribution 4.0 License und Codebeispiele unter der Apache 2.0 License lizenziert. Weitere Informationen finden Sie in den Websiterichtlinien von Google Developers. Java ist eine eingetragene Marke von Oracle und/oder seinen Partnern.
Zuletzt aktualisiert: 2025-09-04 (UTC).
[[["Leicht verständlich","easyToUnderstand","thumb-up"],["Mein Problem wurde gelöst","solvedMyProblem","thumb-up"],["Sonstiges","otherUp","thumb-up"]],[["Benötigte Informationen nicht gefunden","missingTheInformationINeed","thumb-down"],["Zu umständlich/zu viele Schritte","tooComplicatedTooManySteps","thumb-down"],["Nicht mehr aktuell","outOfDate","thumb-down"],["Problem mit der Übersetzung","translationIssue","thumb-down"],["Problem mit Beispielen/Code","samplesCodeIssue","thumb-down"],["Sonstiges","otherDown","thumb-down"]],["Zuletzt aktualisiert: 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)"]]