相機模式

Camera 類別提供設定不同相機模式的方法。導航期間,每種模式檢視地圖的方式都不同。您可以呼叫下列任一方法來設定相機模式:

followMyLocation()
這是導航的預設相機模式。這個模式會設定攝影機跟隨車輛。導航期間,相機會自動面對行駛方向。
setLocation()
平移及縮放相機,將鏡頭對準特定位置。使用這個模式時,您可以設定攝影機位置、相機面對的方向和縮放等級。使用這個相機模式時,畫面上會出現「Re-center」按鈕。
showRouteOverview()
顯示其餘路線的總覽,並視需要平移和縮放,將路線符合地圖檢視。使用這個相機模式時,畫面上會出現「Re-center」按鈕。

按一下「Re-center」按鈕,將相機模式設為跟隨我的位置。

追蹤我的定位模式

這是相機在導航時最常使用的相機模式。在這個相機模式中,您可以透過以下方式查看路線:

  • 車輛一律會向上抬頭,以特定角度的頭頂視角 (Camera.Perspective.TILTED) 顯示。

  • 在地圖上行駛的車輛一律朝向北方,以正上方俯視視角 (Camera.Perspective.TOP_DOWN_NORTH_UP)。

  • 車輛一律會向上抬頭,以垂直俯視視角 (Camera.Perspective.TOP_DOWN_HEADING_UP) 顯示。

以下程式碼範例示範如何將相機模式設為「跟隨我的位置」,並使用角度的俯視視角。

NavFragment.getCamera().followMyLocation(Camera.Perspective.TILTED);

設定定位模式

setLocation 模式可讓開發人員控制最多的相機。在這個模式中,您可以將攝影機放在特定位置、為攝影機檢視畫面方向指派方向,以及設定攝影機的縮放等級。

這個設定包括透過 GPS 座標定義相機的位置,然後包裝位置、相機方位和縮放等級:

// Set up a stationary camera
// Pick a location to place the camera: Seattle Space Needle
double cameraLatitude = 47.6101d;
double cameraLongitude = -122.3421d;  // Use negative for W of Greenwich.

// Package the coordinates
com.google.android.libraries.navigation.LatLng cameraCenter;
cameraCenter = new com.google.android.libraries.navigation.LatLng (cameraLatitude, cameraLongitude);

// Prepare the state info for the setLocation method.
com.google.android.libraries.navigation.CameraPosition newCameraPosition;
newCameraPosition = new com.google.android.libraries.navigation.CameraPosition();

newCameraPosition.center(cameraCenter);
newCameraPosition.bearing(-90.00f); // N 0.00; E 90.00; S 180.00; W 270.0 (or -90.0).
newCameraPosition.zoom(14.0f);      // Zooms to street level (approx.)

boolean animate = true;
mNavFragment.getCamera().setLocation(newCameraPosition, animate);

顯示路線總覽模式

showRouteOverview 相機設定會顯示整個旅程。針對多個目的地旅程,這個模式會顯示路線中未經移動的部分。

// Place the camera to see the remaining route:
mNavFragment.getCamera().showRouteOverview();

後續步驟

請參閱自訂導覽 UI,瞭解如何自訂使用者與地圖的互動方式,進而決定要在地圖上顯示的內建 UI 元件。