调整摄像头
使用集合让一切井井有条
根据您的偏好保存内容并对其进行分类。
借助摄像头,您可以更改用户查看地图的视角。您可以使用相机模式来控制导航期间地图视图的行为。
如需设置相机模式,请调用与相机关联的以下方法之一:
跟随我的位置 (GoogleMap.followMyLocation
) - 导航的默认摄像头模式。此模式将相机设置为设备或车辆。
在导航过程中,摄像头会自动朝向行进方向。
固定到位置(GoogleMap.animateCamera
和 GoogleMap.moveCamera
)- 将相机固定在特定位置。使用此模式时,您可以设置相机位置以及其他相机属性,例如方位、倾斜度、缩放等。选择此视图并初始化 Navigator 后,系统会显示重新居中按钮。
显示路线概览(NavigationView.showRouteOverview
或 SupportNavigationFragment.showRouteOverview
):显示剩余路线的概览(最多为接下来 45 分钟的驾驶时间),并根据需要平移和缩放以将路线纳入地图视图。选择此视图后,系统会显示重新居中按钮。
点击居中按钮会将摄像头设置为 followMyLocation
模式。
遵循我的位置信息模式
最常见的相机设置是将相机设置为设备或车辆,以显示其在行程中的当前位置。在此相机模式下,您可以查看路线,其中汽车始终朝向屏幕上方,并采用倾斜视角 (CameraPerspective.TILTED
);或者,您可以查看汽车的行驶方向,其中北方 (CameraPerspective.TOP_DOWN_NORTH_UP
) 或航向 (CameraPerspective.TOP_DOWN_HEADING_UP)
) 始终位于屏幕顶部。
以下代码段使用了 TILTED
透视:
// Set the camera to follow the device (vehicle):
mNavFragment.getMapAsync(googleMap -> googleMap.followMyLocation(CameraPerspective.TILTED))
固定到位置信息模式
Pinned
模式可让您最大限度地控制相机。在此模式下,您可以将相机放置在特定位置,分配方向角以确定相机视图的方向,更改倾斜度以设置视角,并设置相机的缩放级别。
以下代码段展示了移动镜头的一些常用方法。
private static final LatLng SYDNEY = new LatLng(-33.88, 151.21);
private static final LatLng MOUNTAIN_VIEW = new LatLng(37.4, -122.1);
private GoogleMap map;
... // Obtain the map from a SupportNavigationFragment or NavigationView.
// Move the camera instantly to Sydney with a zoom of 15.
map.moveCamera(CameraUpdateFactory.newLatLngZoom(SYDNEY, 15));
// Zoom in, animating the camera.
map.animateCamera(CameraUpdateFactory.zoomIn());
// Zoom out to zoom level 10, animating with a duration of 2 seconds.
map.animateCamera(CameraUpdateFactory.zoomTo(10), 2000, null);
// Construct a CameraPosition focusing on Mountain View and animate the camera to that position.
CameraPosition cameraPosition = new CameraPosition.Builder()
.target(MOUNTAIN_VIEW) // Sets the center of the map to Mountain View
.zoom(17) // Sets the zoom
.bearing(90) // Sets the orientation of the camera to east
.tilt(30) // Sets the tilt of the camera to 30 degrees
.build(); // Creates a CameraPosition from the builder
map.animateCamera(CameraUpdateFactory.newCameraPosition(cameraPosition));
显示路线概览模式
showRouteOverview
摄像头设置会显示整个行程。
对于多目的地旅程,此模式会显示尚未走完的路线部分。
// Place the camera to see the remaining route:
mNavFragment.showRouteOverview();
下一步
如需了解如何通过确定在地图上显示哪些内置界面组件来定制用户与地图的互动方式,请参阅自定义导航界面。
如未另行说明,那么本页面中的内容已根据知识共享署名 4.0 许可获得了许可,并且代码示例已根据 Apache 2.0 许可获得了许可。有关详情,请参阅 Google 开发者网站政策。Java 是 Oracle 和/或其关联公司的注册商标。
最后更新时间 (UTC):2025-08-31。
[null,null,["最后更新时间 (UTC):2025-08-31。"],[[["\u003cp\u003eThe Navigation SDK offers three camera modes: \u003ccode\u003efollowMyLocation\u003c/code\u003e, \u003ccode\u003ePinned to location\u003c/code\u003e, and \u003ccode\u003eshowRouteOverview\u003c/code\u003e to control the user's viewpoint of the map during navigation.\u003c/p\u003e\n"],["\u003cp\u003e\u003ccode\u003efollowMyLocation\u003c/code\u003e mode centers the map on the user's location and automatically adjusts during navigation, while \u003ccode\u003ePinned to location\u003c/code\u003e mode fixes the camera at a specific location with customizable properties.\u003c/p\u003e\n"],["\u003cp\u003e\u003ccode\u003eshowRouteOverview\u003c/code\u003e mode displays the entire route or remaining route, adjusting the view to fit the route on the screen.\u003c/p\u003e\n"],["\u003cp\u003eYou can customize the camera's perspective, zoom level, bearing, and tilt to enhance the user experience.\u003c/p\u003e\n"],["\u003cp\u003eHigh detail setting, when enabled, displays 2-D building outlines when the zoom level is 19 or higher, which can be further customized using \u003ccode\u003eFollowMyLocationOptions\u003c/code\u003e.\u003c/p\u003e\n"]]],[],null,["# Adjust the camera\n\nThe camera allows you to change the user's viewpoint of the map. You can\nuse camera modes to control the behavior of the map view during navigation.\nTo set the camera mode, call one of the following methods associated\nwith the camera:\n\n- Follow my location (`GoogleMap.followMyLocation`) --- The default camera\n mode for navigation. This mode sets the camera to the device or vehicle.\n During navigation, the camera automatically faces the direction of travel.\n\n- Pinned to location (`GoogleMap.animateCamera` and `GoogleMap.moveCamera`)\n --- Fixes the camera at a specific location. When using this mode, you can\n set the camera location along with other camera properties like bearing, tilt,\n zoom, etc. When this view is selected and the Navigator has been initialized,\n the **Re-center** button is visible.\n\n- Show route overview (`NavigationView.showRouteOverview` or\n `SupportNavigationFragment.showRouteOverview`) --- Displays an overview\n of the remaining route (up to the next 45 minutes of driving time), panning and zooming as needed to fit the route\n into the map view. When this view is selected, the **Re-center** button\n is visible.\n\nClicking the **Re-center** button sets the camera to `followMyLocation` mode.\n\nFollow my location mode\n-----------------------\n\nThe most common camera setting is to have the camera set to the\ndevice or vehicle, showing its current position within the journey. In\nthis camera mode, you can view the route with the car always headed up\nthe screen with an angled perspective (`CameraPerspective.TILTED`), or\nyou can see the car traveling with north (`CameraPerspective.TOP_DOWN_NORTH_UP`)\nor with heading (`CameraPerspective.TOP_DOWN_HEADING_UP)` always at the top of\nthe screen.\n\nThe following code fragment uses the `TILTED` perspective: \n\n // Set the camera to follow the device (vehicle):\n mNavFragment.getMapAsync(googleMap -\u003e googleMap.followMyLocation(CameraPerspective.TILTED))\n\nPinned to location mode\n-----------------------\n\nThe `Pinned` mode provides you with the most control of the\ncamera. In this mode, you place the camera in a specific location, assign\na bearing to orient the camera view, change the tilt to set the viewing angle, and\nset the camera's zoom level.\n\nThe following code snippet demonstrates some of the common ways to move the\ncamera. \n\n private static final LatLng SYDNEY = new LatLng(-33.88, 151.21);\n private static final LatLng MOUNTAIN_VIEW = new LatLng(37.4, -122.1);\n\n private GoogleMap map;\n ... // Obtain the map from a SupportNavigationFragment or NavigationView.\n\n // Move the camera instantly to Sydney with a zoom of 15.\n map.moveCamera(CameraUpdateFactory.newLatLngZoom(SYDNEY, 15));\n\n // Zoom in, animating the camera.\n map.animateCamera(CameraUpdateFactory.zoomIn());\n\n // Zoom out to zoom level 10, animating with a duration of 2 seconds.\n map.animateCamera(CameraUpdateFactory.zoomTo(10), 2000, null);\n\n // Construct a CameraPosition focusing on Mountain View and animate the camera to that position.\n CameraPosition cameraPosition = new CameraPosition.Builder()\n .target(MOUNTAIN_VIEW) // Sets the center of the map to Mountain View\n .zoom(17) // Sets the zoom\n .bearing(90) // Sets the orientation of the camera to east\n .tilt(30) // Sets the tilt of the camera to 30 degrees\n .build(); // Creates a CameraPosition from the builder\n map.animateCamera(CameraUpdateFactory.newCameraPosition(cameraPosition));\n\nShow route overview mode\n------------------------\n\nThe `showRouteOverview` camera setting displays the entire journey.\nFor multiple-destination journeys, this mode displays the untraveled\nportion of the route. \n\n // Place the camera to see the remaining route:\n mNavFragment.showRouteOverview();\n\nNext step\n---------\n\nSee [Customize the Navigation UI](/maps/documentation/navigation/android-sdk/controls)\nto learn how to customize the way in which users interact with your map\nby determining which of the built-in UI components appear on the map."]]