配置地图和相机限制
使用集合让一切井井有条
根据您的偏好保存内容并对其进行分类。
您可能需要创建纬度和经度边界来限制用户在 3D 地图中的移动,或者限制相机的高度、航向或倾斜度。您可以通过配置地图和摄像头限制来实现此目的。
以下代码示例演示了如何使用 Map.cameraRestrictions
方法来限制相机的地理边界以及相机的高度、航向和倾斜度值。
Swift
struct CameraRestrictionDemo: View {
var body: some View {
Map(initialCamera: .sanFrancisco, mode: .hybrid)
.cameraRestrictions([
.bounds(latitude: 37.7...37.8, longitude: (-122.5)...(-122.4))
])
}
}
如未另行说明,那么本页面中的内容已根据知识共享署名 4.0 许可获得了许可,并且代码示例已根据 Apache 2.0 许可获得了许可。有关详情,请参阅 Google 开发者网站政策。Java 是 Oracle 和/或其关联公司的注册商标。
最后更新时间 (UTC):2025-08-31。
[null,null,["最后更新时间 (UTC):2025-08-31。"],[],[],null,["Select platform: [Android](/maps/documentation/maps-3d/android-sdk/map-camera-restrictions \"View this page for the Android platform docs.\") [iOS](/maps/documentation/maps-3d/ios-sdk/map-camera-restrictions \"View this page for the iOS platform docs.\") [JavaScript](/maps/documentation/javascript/3d/interaction \"View this page for the JavaScript platform docs.\")\n\n\u003cbr /\u003e\n\n| This product or feature is Experimental (pre-GA). Pre-GA products and features might have limited support, and changes to pre-GA products and features might not be compatible with other pre-GA versions. Pre-GA Offerings are covered by the [Google\n| Maps Platform Service Specific Terms](https://cloud.google.com/maps-platform/terms/maps-service-terms). For more information, see the [launch stage descriptions](/maps/launch-stages).\n\n\nYou may want to create latitude and longitude boundaries that restrict a user's movement in a 3D\nmap, or to limit the camera's altitude, heading, or tilt. You can do this by configuring map and\ncamera restrictions.\n\nThe following code sample demonstrates how to use the [`Map.cameraRestrictions` method](/maps/documentation/maps-3d/ios-sdk/reference/Extensions/View#camerarestrictions_:) to restrict both the geographical boundaries of the\ncamera and the values of the camera's altitude, heading, and tilt. \n\nSwift \n\n```swift\n struct CameraRestrictionDemo: View {\n var body: some View {\n Map(initialCamera: .sanFrancisco, mode: .hybrid)\n .cameraRestrictions([\n .bounds(latitude: 37.7...37.8, longitude: (-122.5)...(-122.4))\n ])\n }\n }\n \n```"]]