您可以使用标记来显示地图上的单个位置。此页面介绍了如何以程序化方式和使用 HTML 来向地图添加标记。
使用 HTML 添加标记
如需使用 HTML 添加 3D 标记,请在 gmp-map-3d
元素中添加一个 gmp-marker-3d
子元素。下面的代码段显示了如何向网页添加标记:
<gmp-map-3d
mode="hybrid"
center="48.861000,2.335861"
heading="110"
tilt="67.5"
range="1000"
style="height:400px"
>
<gmp-marker-3d
position="48.861000,2.335861">
</gmp-marker-3d>
</gmp-map-3d>
以程序化方式添加标记
如需以程序化方式向地图添加 3D 标记,请创建一个新的 Marker3DElement
,并向其传递 lat/lng
坐标和对基本地图的引用,如以下示例所示:
const marker = new Marker3DElement({
position: {lat: 47.6093, lng: -122.3402}, // (Required) Marker must have a lat/lng.
altitudeMode : "ABSOLUTE", // (Optional) Treated as CLAMP_TO_GROUND if omitted.
extruded : true, // (Optional) Draws line from ground to the bottom of the marker.
label : "Basic Marker" // (Optional) Add a label to the marker.
});
map.append(marker); // The marker must be appended to the map.