配置标记冲突行为
使用集合让一切井井有条
根据您的偏好保存内容并对其进行分类。
您可以自定义添加到 3D 地图中的标记的碰撞行为。
以下代码示例演示了如何配置 Marker
结构的 collisionBehavior
,以指定某个标记与其他标记或地图标签冲突时的行为方式。
Swift
Map(camera: $camera, mode: .hybrid) {
Marker(
position: .init(
latitude: 37.794724,
longitude: -122.39442,
altitude: 100.0),
altitudeMode: .relativeToMesh,
collisionBehavior: .optionalAndHidesLowerPriority,
extruded: true,
label: "Marker 1"
)
Marker(
position: .init(
latitude: 37.7943220,
longitude: -122.395073,
altitude: 100.0),
altitudeMode: .relativeToMesh,
collisionBehavior: .required,
extruded: true,
label: "Marker 2"
)
Marker(
position: .init(
latitude: 37.7934108,
longitude: -122.396144,
altitude: 100.0),
altitudeMode: .relativeToMesh,
collisionBehavior: .requiredAndHidesOptional,
extruded: true,
label: "Marker 3"
)
}
如未另行说明,那么本页面中的内容已根据知识共享署名 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/configure-marker-collision-behavior \"View this page for the Android platform docs.\") [iOS](/maps/documentation/maps-3d/ios-sdk/configure-marker-collision-behavior \"View this page for the iOS platform docs.\") [JavaScript](/maps/documentation/javascript/3d/marker-collision \"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 can customize the collision behavior of markers that you add to a 3D map.\n\nThe following code sample demonstrates how configure the [`collisionBehavior` of the `Marker` struct](/maps/documentation/maps-3d/ios-sdk/reference/Structs/Marker#collisionbehavior) to specify how a marker should behave when it collides with anothermarker or map label. \n\nSwift\n\n```\nMap(camera: $camera, mode: .hybrid) {\n Marker(\n position: .init(\n latitude: 37.794724,\n longitude: -122.39442,\n altitude: 100.0),\n altitudeMode: .relativeToMesh,\n collisionBehavior: .optionalAndHidesLowerPriority,\n extruded: true,\n label: \"Marker 1\"\n )\n \n Marker(\n position: .init(\n latitude: 37.7943220,\n longitude: -122.395073,\n altitude: 100.0),\n altitudeMode: .relativeToMesh,\n collisionBehavior: .required,\n extruded: true,\n label: \"Marker 2\"\n )\n \n Marker(\n position: .init(\n latitude: 37.7934108,\n longitude: -122.396144,\n altitude: 100.0),\n altitudeMode: .relativeToMesh,\n collisionBehavior: .requiredAndHidesOptional,\n extruded: true,\n label: \"Marker 3\"\n )\n}\n \n```"]]