标记
使用集合让一切井井有条
根据您的偏好保存内容并对其进行分类。
使用标记吸引用户关注地图上的某个位置。本指南介绍了如何在 3D 地图中使用和自定义标记,除了标记出现的海拔高度外,您还可以控制标记的形状、大小和颜色。
在地图上使用标记显示位置。上面的示例展示了一个基本的单个标记,未应用任何自定义设置。
自定义颜色、比例和图标图片
自定义默认标记的背景、字形、边框颜色和大小。

将默认标记图标替换为自定义 SVG 资源。

设置标记的海拔高度
您可以通过拉伸标记并设置海拔高度来设置标记的海拔高度。

让标记响应点击事件和键盘事件
通过添加 click
事件监听器,使标记响应点击和键盘事件。
function initMap() {
const map = new Map3DElement({
center: { lat: 37.4690, lng: -122.1074, altitude: 0 },
tilt: 67.5,
range: 45000,
mode: MapMode.HYBRID
});
const interactiveMarker = new google.maps.marker.Marker3DInteractiveElement({
map,
position: {lat: 37.4239163, lng: -122.0947209},
});
interactiveMarker.addEventListener('gmp-click', (event) => {
// Handle the click event.
// ...
});
}
设置标记冲突行为
指定某个标记与其他标记或地图标签冲突时的行为方式。
const marker = new Marker3DElement({
position: {lat, lng},
collisionBehavior: google.maps.CollisionBehavior.REQUIRED
});
下一步
如未另行说明,那么本页面中的内容已根据知识共享署名 4.0 许可获得了许可,并且代码示例已根据 Apache 2.0 许可获得了许可。有关详情,请参阅 Google 开发者网站政策。Java 是 Oracle 和/或其关联公司的注册商标。
最后更新时间 (UTC):2025-04-29。
[null,null,["最后更新时间 (UTC):2025-04-29。"],[],[],null,["\u003cbr /\u003e\n\n| This product or feature is in Preview (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\n| descriptions](/maps/launch-stages).\n\n\u003cbr /\u003e\n\nUse markers to draw a user's attention to a location on a map. This guide\ndemonstrates how to use and customize markers in 3D maps. You can control the\nshape, size, and color of markers, in addition to the altitude at which they\nappear.\n\nUse markers to show locations on maps. The example above shows a basic, single\nmarker with no customization applied.\n\nCustomize color, scale and icon image\n\nCustomize the default marker's background, glyph, border color, and size.\n\nReplace the default marker icon with a custom SVG resource.\n\nSet marker altitude\n\nYou can set marker altitude by extruding the marker and setting the altitude.\n\nMake markers respond to click and keyboard events\n\nMake a marker respond to clicks and keyboard events by adding a `click` event\nlistener. \n\n function initMap() {\n const map = new Map3DElement({\n center: { lat: 37.4690, lng: -122.1074, altitude: 0 },\n tilt: 67.5,\n range: 45000,\n mode: MapMode.HYBRID\n });\n\n const interactiveMarker = new google.maps.marker.Marker3DInteractiveElement({\n map,\n position: {lat: 37.4239163, lng: -122.0947209},\n });\n\n interactiveMarker.addEventListener('gmp-click', (event) =\u003e {\n // Handle the click event.\n // ...\n });\n }\n\nSet marker collision behavior\n\nSpecify how a marker should behave when it collides with another marker or map\nlabel. \n\n const marker = new Marker3DElement({\n position: {lat, lng},\n collisionBehavior: google.maps.CollisionBehavior.REQUIRED\n });\n\nNext step\n\n- [Add a marker](/maps/documentation/javascript/3d/marker-add)"]]