마커를 사용하여 지도에서 단일 위치를 표시하세요. 이 페이지에서는 프로그래매틱 방식 및 HTML을 통해 지도에 마커를 추가하는 방법을 설명합니다.
HTML을 사용하여 마커 추가하기
HTML을 사용하여 3D 마커를 추가하려면 gmp-map-3d 요소에 gmp-marker-3d 하위 요소를 추가합니다. 다음 스니펫은 웹페이지에 마커를 추가하는 방법을 보여줍니다.
<html>
<head>
<title>3D Marker HTML</title>
<link rel="stylesheet" type="text/css" href="./style.css" />
<script
async
src="https://maps.googleapis.com/maps/api/js?loading=async&key=AIzaSyA6myHzS10YXdcazAFalmXvDkrYCp5cLc8&libraries=maps3d"></script>
</head>
<body>
<gmp-map-3d
center="40.7489,-73.9680,0"
heading="315"
tilt="65"
range="800"
mode="SATELLITE">
<gmp-marker position="40.7489,-73.9680" title="UN Headquarters">
<div class="custom-marker">
United Nations Secretariat Building
</div>
</gmp-marker>
</gmp-map-3d>
</body>
</html>프로그래매틱 방식으로 마커 추가하기
프로그래매틱 방식으로 지도에 3D 마커를 추가하려면 다음 예와 같이 새 Marker3DElement를 만들어 lat/lng 좌표와 참조를 기본 지도에 전달합니다.
async function init() { // Make sure the Marker3DElement is included. const { Map3DElement, Marker3DElement } = await google.maps.importLibrary('maps3d'); const map = new Map3DElement({ center: { lat: 37.4239163, lng: -122.0947209, altitude: 0 }, tilt: 67.5, range: 1000, mode: 'SATELLITE', gestureHandling: 'COOPERATIVE', }); const marker = new Marker3DElement({ position: { lat: 37.4239163, lng: -122.0947209, altitude: 50 }, // (Required) Marker must have a lat / lng, but doesn't need an altitude. 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. document.body.append(map); } void init();