Skip to content

Commit 3c6b9cb

Browse files
authored
feat: Updates markers altitude sample to use the gmp-map element. (#823)
* feat: Updates markers altitude sample to use the gmp-map element. Change-Id: Ic1facde6bad67017392c8203241e91f87d891c7b * Refactor innerMap options setting * Refactor to remove innerMap var * Update copyright year and marker variable name * Update marker creation to append pin element
1 parent ca0e8d5 commit 3c6b9cb

File tree

2 files changed

+14
-15
lines changed

2 files changed

+14
-15
lines changed
Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<!doctype html>
1+
<!DOCTYPE html>
22
<!--
33
@license
44
Copyright 2019 Google LLC. All Rights Reserved.
@@ -11,13 +11,12 @@
1111

1212
<link rel="stylesheet" type="text/css" href="./style.css" />
1313
<script type="module" src="./index.js"></script>
14-
</head>
15-
<body>
16-
<div id="map"></div>
17-
1814
<!-- prettier-ignore -->
1915
<script>(g=>{var h,a,k,p="The Google Maps JavaScript API",c="google",l="importLibrary",q="__ib__",m=document,b=window;b=b[c]||(b[c]={});var d=b.maps||(b.maps={}),r=new Set,e=new URLSearchParams,u=()=>h||(h=new Promise(async(f,n)=>{await (a=m.createElement("script"));e.set("libraries",[...r]+"");for(k in g)e.set(k.replace(/[A-Z]/g,t=>"_"+t[0].toLowerCase()),g[k]);e.set("callback",c+".maps."+q);a.src=`https://maps.${c}apis.com/maps/api/js?`+e;d[q]=f;a.onerror=()=>h=n(Error(p+" could not load."));a.nonce=m.querySelector("script[nonce]")?.nonce||"";m.head.append(a)}));d[l]?console.warn(p+" only loads once. Ignoring:",g):d[l]=(f,...n)=>r.add(f)&&u().then(()=>d[l](f,...n))})
2016
({key: "AIzaSyA6myHzS10YXdcazAFalmXvDkrYCp5cLc8", v: "weekly"});</script>
17+
</head>
18+
<body>
19+
<gmp-map center="47.65196191658531,-122.30716770065949" zoom="19" map-id="6ff586e93e18149f"></gmp-map>
2120
</body>
2221
</html>
2322
<!-- [END maps_advanced_markers_altitude] -->
Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,22 @@
11
/**
22
* @license
3-
* Copyright 2019 Google LLC. All Rights Reserved.
3+
* Copyright 2025 Google LLC. All Rights Reserved.
44
* SPDX-License-Identifier: Apache-2.0
55
*/
66

77
// [START maps_advanced_markers_altitude]
8-
let map;
8+
const mapElement = document.querySelector('gmp-map') as google.maps.MapElement;
9+
910
async function initMap() {
1011
// Request needed libraries.
1112
const { Map } = await google.maps.importLibrary("maps") as google.maps.MapsLibrary;
1213
const { AdvancedMarkerElement, PinElement } = await google.maps.importLibrary("marker") as google.maps.MarkerLibrary;
1314

14-
map = new Map(document.getElementById('map') as HTMLElement, {
15-
center: {lat: 47.65196191658531, lng: -122.30716770065949},
16-
zoom: 19,
15+
mapElement.innerMap.setOptions ({
1716
tilt: 67.5,
1817
heading: 45,
19-
mapId: '6ff586e93e18149f',
2018
});
19+
2120
// [START maps_advanced_markers_altitude_marker]
2221
const pin = new PinElement({
2322
background: '#4b2e83',
@@ -26,14 +25,15 @@ async function initMap() {
2625
scale: 2.0,
2726
});
2827

29-
const markerView = new AdvancedMarkerElement({
30-
map,
31-
content: pin.element,
28+
const marker = new AdvancedMarkerElement({
3229
// Set altitude to 20 meters above the ground.
3330
position: { lat: 47.65170843460547, lng: -122.30754, altitude: 20 } as google.maps.LatLngAltitudeLiteral,
3431
});
32+
marker.append(pin);
33+
34+
mapElement.append(marker);
3535
// [END maps_advanced_markers_altitude_marker]
3636
}
3737

3838
initMap();
39-
// [END maps_advanced_markers_altitude]
39+
// [END maps_advanced_markers_altitude]

0 commit comments

Comments
 (0)