Migration for Android Consumer SDK 1.0 自訂項目

自訂標記

在舊版 Consumer SDK 中,您使用了 Consumer SDK 的 MarkerStyleOptions 物件來自訂標記樣式屬性。在消費者 SDK 1.0 版中,您可以直接使用 Maps SDK 中的 MarkerOptions 物件。

// Centering the marker anchor at (0.5, 0.5) is recommended.
// For vehicle markers, set flat to true to allow the vehicle marker to freely
// rotate flat on the map (rather than always have it face the camera).
MarkerOptions vehicleMarkerOptions = new MarkerOptions()
    .flat(true)
    .anchor(0.5f, 0.5f)
    .icon(vehicleIcon)
    .zIndex(1.0f);
consumerMapStyle.setMarkerStyleOptions(MarkerType.TRIP_VEHICLE);

如果尚未設定樣式,或樣式選項設為 nullConsumerMapStyle 會傳回 SDK 為特定標記類型指定的預設樣式選項。

// ConsumerMapStyle returns the SDK-set default style options if none has been set yet.
MarkerOptions defaultPickupPointStyleOptions = consumerMapStyle.getMarkerStyleOptions(MarkerType.PICKUP_POINT);

// Setting the style to null reverts the style back to the SDK-set default properties.
consumerMapStyle.setMarkerStyleOptions(MarkerType.PICKUP_POINT, /* markerStyleOptions= */ null);
MarkerOptions defaultPickupPointStyleOptions = consumerMapStyle.getMarkerStyleOptions(MarkerType.PICKUP_POINT);

如果您不想從頭開始建立新樣式,可以修改預設樣式。以下範例只會修改取貨圖示,並針對其餘標記選項使用 SDK 的預設設定。

// getMarkerStyleOptions returns the default pickup point style options, since
// the custom style hasn't been set yet.
MarkerOptions pickupPointStyleOptions =
  consumerMapStyle.getMarkerStyleOptions(MarkerType.PICKUP_POINT);
// Modify the icon value and set the style.
consumerMapStyle.setMarkerStyleOptions(
  pickupPointStyleOptions.icon(pickupPointIcon));

折線自訂功能

在舊版 Consumer SDK 中,您使用了 Consumer SDK 的 PolylineStyleOptions 物件來自訂折線樣式屬性。在 Consumer SDK 1.0 版中,您可以使用 Maps SDK 的 PolylineOptions 物件,自訂基本折線樣式屬性和 TrafficStyle 物件,自訂折線流量顏色。

消費者 SDK 1.0 版中的 Alpha 變化版本提供車流量折線。如果可見流量,基本折線顏色就會遭到流量顏色覆寫。預設不會顯示流量。TrafficStyle 中的未設定欄位則會由 SDK 指定的預設值填入。

// PolylineOptions is from Maps SDK
PolylineOptions polylineOptions = new PolylineOptions()
  .color(color)
  .width(width)
  .geodesic(geodesic)
  .startCap(startCap)
  .endCap(endCap)
  .zIndex(zIndex);
consumerMapStyle.setPolylineStyleOptions(
  PolylineType.ACTIVE_ROUTE, polylineOptions);

// TrafficStyle is from ConsumerSDK
TrafficStyle trafficStyle = TrafficStyle.builder()
  .setTrafficVisibility(true)
  .setTrafficColor(SpeedType.NO_DATA, Color.GREY)
  .setTrafficColor(SpeedType.NORMAL_VALUE, Color.BLUE)
  .setTrafficColor(SpeedType.SLOW_VALUE, Color.ORANGE)
  .setTrafficColor(SpeedType.TRAFFIC_JAM, Color.RED)
  .build();
consumerMapStyle.setPolylineTrafficStyle(PolylineType.ACTIVE_ROUTE, trafficStyle);

如果尚未設定任何折線類型,或樣式選項設為 nullConsumerMapStyle 會傳回 SDK 特定折線類型的預設樣式選項。這同時適用於基本 PolylineOptionsTrafficStyle

// ConsumerMapStyle returns the SDK's default style options if none has been set yet.
PolylineOptions defaultActiveRouteStyleOptions = consumerMapStyle.getPolylineStyleOptions(PolylineType.ACTIVE_ROUTE);

// Setting the style to null reverts the style back to the SDK-set default properties.
consumerMapStyle.setPolylineStyleOptions(
  PolylineType.ACTIVE_ROUTE, /* polylineStyleOptions= */ null);
PolylineOptions defaultActiveRouteStyleOptions =
  consumerMapStyle.getPolylineStyleOptions(PolylineType.ACTIVE_ROUTE);

如果您不想從頭開始建立新樣式,可以修改預設樣式。以下範例只會修改基本有效路線折線顏色,其餘標記選項則使用 SDK 的預設樣式設定。

// Only customize the remaining route polyline color.
PolylineOptions remainingRouteStyleOptions =
     consumerMapStyle.getPolylineStyleOptions(PolylineType.REMAINING_ROUTE);
consumerMapStyle.setPolylineStyleOptions(
  remainingRouteStyleOptions.color(Color.DARK_BLUE));