ปรับกล้อง
จัดทุกอย่างให้เป็นระเบียบอยู่เสมอด้วยคอลเล็กชัน
บันทึกและจัดหมวดหมู่เนื้อหาตามค่ากำหนดของคุณ
กล้องช่วยให้คุณเปลี่ยนมุมมองของผู้ใช้ในแผนที่ได้ คุณ
ใช้โหมดกล้องเพื่อควบคุมลักษณะการทำงานของมุมมองแผนที่ในระหว่างการนำทางได้
หากต้องการตั้งค่าโหมดกล้อง ให้เรียกใช้เมธอดใดเมธอดหนึ่งต่อไปนี้ที่เชื่อมโยง
กับกล้อง
ติดตามตำแหน่งของฉัน (GoogleMap.followMyLocation
) — โหมดกล้องเริ่มต้น
สำหรับการนำทาง โหมดนี้จะตั้งค่ากล้องเป็นอุปกรณ์หรือยานพาหนะ
ในระหว่างการนำทาง กล้องจะหันไปในทิศทางการเดินทางโดยอัตโนมัติ
ปักหมุดไว้กับตำแหน่ง (GoogleMap.animateCamera
และ GoogleMap.moveCamera
)
- กล้องจะอยู่กับที่ในตำแหน่งที่เฉพาะเจาะจง เมื่อใช้โหมดนี้ คุณจะ
ตั้งค่าตำแหน่งกล้องพร้อมกับพร็อพเพอร์ตี้อื่นๆ ของกล้อง เช่น ทิศทาง เอียง
ซูม ฯลฯ เมื่อเลือกมุมมองนี้และเริ่มต้นเนวิเกเตอร์แล้ว
ปุ่มจัดกึ่งกลางอีกครั้งจะปรากฏขึ้น
แสดงภาพรวมของเส้นทาง (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();
ขั้นตอนถัดไป
ดูปรับแต่ง UI การนำทาง
เพื่อดูวิธีปรับแต่งวิธีที่ผู้ใช้โต้ตอบกับแผนที่
โดยการกำหนดว่าคอมโพเนนต์ UI ในตัวใดจะปรากฏบนแผนที่
เนื้อหาของหน้าเว็บนี้ได้รับอนุญาตภายใต้ใบอนุญาตที่ต้องระบุที่มาของครีเอทีฟคอมมอนส์ 4.0 และตัวอย่างโค้ดได้รับอนุญาตภายใต้ใบอนุญาต Apache 2.0 เว้นแต่จะระบุไว้เป็นอย่างอื่น โปรดดูรายละเอียดที่นโยบายเว็บไซต์ Google Developers Java เป็นเครื่องหมายการค้าจดทะเบียนของ Oracle และ/หรือบริษัทในเครือ
อัปเดตล่าสุด 2025-08-31 UTC
[null,null,["อัปเดตล่าสุด 2025-08-31 UTC"],[[["\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."]]