如何在谷歌地图应用中限制用户仅查看菲律宾锡基霍尔岛
Hey there! Let's tackle this problem step by step. You've got a single coordinate for Siquijor Island, but to restrict your Google Map to only show the island, you'll need to define a LatLngBounds that covers the entire island—just like the Adelaide example you shared.
Step 1: Get Siquijor's Boundary Coordinates
The coordinate you have (9.1999° N, 123.5952° E) is the island's approximate center, but we need the southwest and northeast corner coordinates to create a proper bounds. Here are the approximate bounds for Siquijor (you can refine these by clicking the island's corners in Google Maps to get exact coordinates):
- Southwest corner:
LatLng(9.1138, 123.5142) - Northeast corner:
LatLng(9.2862, 123.6758)
Step 2: Create the LatLngBounds Object
Follow the same pattern as the Adelaide example to define your private bounds object:
// Create LatLngBounds covering Siquijor Island private LatLngBounds SIQUIJOR = new LatLngBounds( new LatLng(9.1138, 123.5142), // Southwest corner new LatLng(9.2862, 123.6758) // Northeast corner );
Step 3: Apply the Bounds to Your mMap Instance
Now you can use this bounds to lock the map to Siquijor in two key ways:
- Set the initial camera view to fit the island:
// Add padding (in pixels) to avoid cutting off UI elements like action bars int padding = 50; CameraUpdate cameraUpdate = CameraUpdateFactory.newLatLngBounds(SIQUIJOR, padding); mMap.moveCamera(cameraUpdate);
- Prevent users from panning/zooming outside the island:
// Restrict all camera movement to stay within Siquijor's bounds mMap.setLatLngBoundsForCameraTarget(SIQUIJOR);
Pro Tip for Better Precision
If you need ultra-accurate bounds:
- Open Google Maps, navigate to Siquijor, right-click the island's extreme corners to copy their exact coordinates.
- Use a tool like OpenStreetMap to extract the island's polygon boundaries, then calculate the minimum/maximum latitudes and longitudes to form your bounds.
内容的提问来源于stack exchange,提问作者Exc3m1206

