diff --git a/dist/index.html b/dist/index.html
index 32a03d1d..54a4c17e 100644
--- a/dist/index.html
+++ b/dist/index.html
@@ -66,6 +66,7 @@
Maps JSAPI Samples
routes-get-alternatives
routes-get-directions
routes-get-directions-panel
+ routes-markers
routes-route-matrix
test-example
ui-kit-customization
diff --git a/dist/samples/routes-markers/app/.eslintsrc.json b/dist/samples/routes-markers/app/.eslintsrc.json
new file mode 100644
index 00000000..4c44dab0
--- /dev/null
+++ b/dist/samples/routes-markers/app/.eslintsrc.json
@@ -0,0 +1,13 @@
+{
+ "extends": [
+ "plugin:@typescript-eslint/recommended"
+ ],
+ "parser": "@typescript-eslint/parser",
+ "rules": {
+ "@typescript-eslint/ban-ts-comment": 0,
+ "@typescript-eslint/no-this-alias": 1,
+ "@typescript-eslint/no-empty-function": 1,
+ "@typescript-eslint/explicit-module-boundary-types": 1,
+ "@typescript-eslint/no-unused-vars": 1
+ }
+}
diff --git a/dist/samples/routes-markers/app/README.md b/dist/samples/routes-markers/app/README.md
new file mode 100644
index 00000000..62904810
--- /dev/null
+++ b/dist/samples/routes-markers/app/README.md
@@ -0,0 +1,33 @@
+# Google Maps JavaScript Sample
+
+This sample is generated from @googlemaps/js-samples located at
+https://github.com/googlemaps-samples/js-api-samples.
+
+## Setup
+
+### Before starting run:
+
+`$npm i`
+
+### Run an example on a local web server
+
+First `cd` to the folder for the sample to run, then:
+
+`$npm start`
+
+### Build an individual example
+
+From `samples/`:
+
+`$npm run build --workspace=sample-name/`
+
+### Build all of the examples.
+
+From `samples/`:
+`$npm run build-all`
+
+## Feedback
+
+For feedback related to this sample, please open a new issue on
+[GitHub](https://github.com/googlemaps-samples/js-api-samples/issues).
+
diff --git a/dist/samples/routes-markers/app/index.html b/dist/samples/routes-markers/app/index.html
new file mode 100644
index 00000000..8f7862e5
--- /dev/null
+++ b/dist/samples/routes-markers/app/index.html
@@ -0,0 +1,22 @@
+
+
+
+
+
+ Get directions
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/dist/samples/routes-markers/app/index.ts b/dist/samples/routes-markers/app/index.ts
new file mode 100644
index 00000000..75fd27e2
--- /dev/null
+++ b/dist/samples/routes-markers/app/index.ts
@@ -0,0 +1,124 @@
+/*
+ * @license
+ * Copyright 2025 Google LLC. All Rights Reserved.
+ * SPDX-License-Identifier: Apache-2.0
+ */
+// [START maps_routes_markers]
+let mapPolylines: google.maps.Polyline[] = [];
+const mapElement = document.querySelector('gmp-map') as google.maps.MapElement;
+let innerMap;
+
+// Initialize and add the map.
+async function initMap() {
+ // Request the needed libraries.
+ await google.maps.importLibrary('maps');
+
+ innerMap = await mapElement.innerMap;
+ innerMap.setOptions({
+ mapTypeControl: false,
+ mapId: 'DEMO_MAP_ID',
+ });
+
+ // Call the function after the map is loaded.
+ google.maps.event.addListenerOnce(innerMap, 'idle', () => {
+ getDirections();
+ });
+}
+
+async function getDirections() {
+ //@ts-ignore
+ // Request the needed libraries.
+ const [{ Route }, { PinElement }] = await Promise.all([
+ google.maps.importLibrary('routes'),
+ google.maps.importLibrary('marker'),
+ ]);
+
+ // [START maps_routes_markers_request_full]
+ // [START maps_routes_markers_request]
+ // Define routes request with an intermediate stop.
+ const request = {
+ origin: 'Parking lot, Christmas Tree Point Rd, San Francisco, CA 94131',
+ destination: '100 Spinnaker Dr, Sausalito, CA 94965', // We're having a yummy lunch!
+ intermediates: [{ location: '300 Finley Rd San Francisco, CA 94129' }], // But first, we golf!
+ travelMode: 'DRIVING',
+ fields: ['path', 'legs', 'viewport'],
+ };
+ // [END maps_routes_markers_request]
+
+ // Call computeRoutes to get the directions.
+ const result = await Route.computeRoutes(request);
+ if (!result.routes || result.routes.length === 0) {
+ console.warn("No routes found");
+ return;
+ }
+ // [END maps_routes_markers_request_full]
+
+ // [START maps_routes_markers_style_maker]
+ // Alter style based on marker index.
+ function markerOptionsMaker(
+ defaultOptions: google.maps.marker.AdvancedMarkerElementOptions,
+ //@ts-ignore
+ waypointMarkerDetails: google.maps.routes.WaypointMarkerDetails
+ ) {
+ const { index, totalMarkers, leg } = waypointMarkerDetails;
+
+ // Style the origin waypoint.
+ if (index === 0) {
+ return {
+ ...defaultOptions,
+ map: innerMap,
+ content: new PinElement({
+ glyph: (index + 1).toString(),
+ glyphColor: 'white',
+ background: 'green',
+ borderColor: 'green',
+ }).element
+ }
+ }
+
+ // Style all intermediate waypoints.
+ if (!(index === 0 || index === totalMarkers - 1)) {
+ return {
+ ...defaultOptions,
+ map: innerMap,
+ content: new PinElement({
+ glyph: (index + 1).toString(),
+ glyphColor: 'white',
+ background: 'blue',
+ borderColor: 'blue',
+ }).element
+ }
+ }
+
+ // Style the destination waypoint.
+ if (index === totalMarkers - 1) {
+ return {
+ ...defaultOptions,
+ map: innerMap,
+ content: new PinElement({
+ glyph: (index + 1).toString(),
+ glyphColor: 'white',
+ background: 'red',
+ borderColor: 'red',
+ }).element
+ }
+ }
+
+ return { ...defaultOptions, map: innerMap };
+ }
+
+ const markers = await result.routes[0].createWaypointAdvancedMarkers(markerOptionsMaker);
+ // [END maps_routes_markers_style_maker]
+
+
+ // Fit the map to the route.
+ innerMap.fitBounds(result.routes[0].viewport);
+ innerMap.setHeading(270);
+
+ // Create polylines and add them to the map.
+ mapPolylines = result.routes[0].createPolylines();
+ mapPolylines.forEach((polyline) => polyline.setMap(innerMap));
+}
+
+initMap();
+// [END maps_routes_markers]
diff --git a/dist/samples/routes-markers/app/package.json b/dist/samples/routes-markers/app/package.json
new file mode 100644
index 00000000..edb83f86
--- /dev/null
+++ b/dist/samples/routes-markers/app/package.json
@@ -0,0 +1,14 @@
+{
+ "name": "@js-api-samples/routes-markers",
+ "version": "1.0.0",
+ "scripts": {
+ "build": "tsc && bash ../jsfiddle.sh routes-markers && bash ../app.sh routes-markers && bash ../docs.sh routes-markers && npm run build:vite --workspace=. && bash ../dist.sh routes-markers",
+ "test": "tsc && npm run build:vite --workspace=.",
+ "start": "tsc && vite build --base './' && vite",
+ "build:vite": "vite build --base './'",
+ "preview": "vite preview"
+ },
+ "dependencies": {
+
+ }
+}
diff --git a/dist/samples/routes-markers/app/style.css b/dist/samples/routes-markers/app/style.css
new file mode 100644
index 00000000..14e92720
--- /dev/null
+++ b/dist/samples/routes-markers/app/style.css
@@ -0,0 +1,24 @@
+/*
+ * @license
+ * Copyright 2025 Google LLC. All Rights Reserved.
+ * SPDX-License-Identifier: Apache-2.0
+ */
+/* [START maps_routes_markers] */
+/*
+ * Always set the map height explicitly to define the size of the div element
+ * that contains the map.
+ */
+#map {
+ height: 100%;
+}
+
+/*
+ * Optional: Makes the sample page fill the window.
+ */
+html,
+body {
+ height: 100%;
+ margin: 0;
+ padding: 0;
+}
+/* [END maps_routes_markers] */
diff --git a/dist/samples/routes-markers/app/tsconfig.json b/dist/samples/routes-markers/app/tsconfig.json
new file mode 100644
index 00000000..09179087
--- /dev/null
+++ b/dist/samples/routes-markers/app/tsconfig.json
@@ -0,0 +1,17 @@
+{
+ "compilerOptions": {
+ "module": "esnext",
+ "target": "esnext",
+ "strict": true,
+ "noImplicitAny": false,
+ "lib": [
+ "es2015",
+ "esnext",
+ "es6",
+ "dom",
+ "dom.iterable"
+ ],
+ "moduleResolution": "Node",
+ "jsx": "preserve"
+ }
+ }
\ No newline at end of file
diff --git a/dist/samples/routes-markers/dist/assets/index-BP2BsdRL.js b/dist/samples/routes-markers/dist/assets/index-BP2BsdRL.js
new file mode 100644
index 00000000..d2f4ae7f
--- /dev/null
+++ b/dist/samples/routes-markers/dist/assets/index-BP2BsdRL.js
@@ -0,0 +1,5 @@
+(function(){const n=document.createElement("link").relList;if(n&&n.supports&&n.supports("modulepreload"))return;for(const r of document.querySelectorAll('link[rel="modulepreload"]'))o(r);new MutationObserver(r=>{for(const e of r)if(e.type==="childList")for(const a of e.addedNodes)a.tagName==="LINK"&&a.rel==="modulepreload"&&o(a)}).observe(document,{childList:!0,subtree:!0});function s(r){const e={};return r.integrity&&(e.integrity=r.integrity),r.referrerPolicy&&(e.referrerPolicy=r.referrerPolicy),r.crossOrigin==="use-credentials"?e.credentials="include":r.crossOrigin==="anonymous"?e.credentials="omit":e.credentials="same-origin",e}function o(r){if(r.ep)return;r.ep=!0;const e=s(r);fetch(r.href,e)}})();/*
+ * @license
+ * Copyright 2025 Google LLC. All Rights Reserved.
+ * SPDX-License-Identifier: Apache-2.0
+ */let u=[];const p=document.querySelector("gmp-map");let t;async function d(){await google.maps.importLibrary("maps"),t=await p.innerMap,t.setOptions({mapTypeControl:!1,mapId:"DEMO_MAP_ID"}),google.maps.event.addListenerOnce(t,"idle",()=>{m()})}async function m(){const[{Route:l},{PinElement:n}]=await Promise.all([google.maps.importLibrary("routes"),google.maps.importLibrary("marker")]),s={origin:"Parking lot, Christmas Tree Point Rd, San Francisco, CA 94131",destination:"100 Spinnaker Dr, Sausalito, CA 94965",intermediates:[{location:"300 Finley Rd San Francisco, CA 94129"}],travelMode:"DRIVING",fields:["path","legs","viewport"]},o=await l.computeRoutes(s);if(!o.routes||o.routes.length===0){console.warn("No routes found");return}function r(e,a){const{index:i,totalMarkers:c,leg:g}=a;return i===0?{...e,map:t,content:new n({glyph:(i+1).toString(),glyphColor:"white",background:"green",borderColor:"green"}).element}:i===0||i===c-1?i===c-1?{...e,map:t,content:new n({glyph:(i+1).toString(),glyphColor:"white",background:"red",borderColor:"red"}).element}:{...e,map:t}:{...e,map:t,content:new n({glyph:(i+1).toString(),glyphColor:"white",background:"blue",borderColor:"blue"}).element}}await o.routes[0].createWaypointAdvancedMarkers(r),t.fitBounds(o.routes[0].viewport),t.setHeading(270),u=o.routes[0].createPolylines(),u.forEach(e=>e.setMap(t))}d();
diff --git a/dist/samples/routes-markers/dist/assets/index-kz-ac4rW.css b/dist/samples/routes-markers/dist/assets/index-kz-ac4rW.css
new file mode 100644
index 00000000..c4e6ccdb
--- /dev/null
+++ b/dist/samples/routes-markers/dist/assets/index-kz-ac4rW.css
@@ -0,0 +1,5 @@
+/*
+ * @license
+ * Copyright 2025 Google LLC. All Rights Reserved.
+ * SPDX-License-Identifier: Apache-2.0
+ */#map{height:100%}html,body{height:100%;margin:0;padding:0}
diff --git a/dist/samples/routes-markers/dist/index.html b/dist/samples/routes-markers/dist/index.html
new file mode 100644
index 00000000..6d32bcb2
--- /dev/null
+++ b/dist/samples/routes-markers/dist/index.html
@@ -0,0 +1,22 @@
+
+
+
+
+
+ Get directions
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/dist/samples/routes-markers/docs/index.html b/dist/samples/routes-markers/docs/index.html
new file mode 100644
index 00000000..8f7862e5
--- /dev/null
+++ b/dist/samples/routes-markers/docs/index.html
@@ -0,0 +1,22 @@
+
+
+
+
+
+ Get directions
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/dist/samples/routes-markers/docs/index.js b/dist/samples/routes-markers/docs/index.js
new file mode 100644
index 00000000..ac2675fa
--- /dev/null
+++ b/dist/samples/routes-markers/docs/index.js
@@ -0,0 +1,107 @@
+"use strict";
+/*
+ * @license
+ * Copyright 2025 Google LLC. All Rights Reserved.
+ * SPDX-License-Identifier: Apache-2.0
+ */
+// [START maps_routes_markers]
+let mapPolylines = [];
+const mapElement = document.querySelector('gmp-map');
+let innerMap;
+// Initialize and add the map.
+async function initMap() {
+ // Request the needed libraries.
+ await google.maps.importLibrary('maps');
+ innerMap = await mapElement.innerMap;
+ innerMap.setOptions({
+ mapTypeControl: false,
+ mapId: 'DEMO_MAP_ID',
+ });
+ // Call the function after the map is loaded.
+ google.maps.event.addListenerOnce(innerMap, 'idle', () => {
+ getDirections();
+ });
+}
+async function getDirections() {
+ //@ts-ignore
+ // Request the needed libraries.
+ const [{ Route }, { PinElement }] = await Promise.all([
+ google.maps.importLibrary('routes'),
+ google.maps.importLibrary('marker'),
+ ]);
+ // [START maps_routes_markers_request_full]
+ // [START maps_routes_markers_request]
+ // Define routes request with an intermediate stop.
+ const request = {
+ origin: 'Parking lot, Christmas Tree Point Rd, San Francisco, CA 94131',
+ destination: '100 Spinnaker Dr, Sausalito, CA 94965', // We're having a yummy lunch!
+ intermediates: [{ location: '300 Finley Rd San Francisco, CA 94129' }], // But first, we golf!
+ travelMode: 'DRIVING',
+ fields: ['path', 'legs', 'viewport'],
+ };
+ // [END maps_routes_markers_request]
+ // Call computeRoutes to get the directions.
+ const result = await Route.computeRoutes(request);
+ if (!result.routes || result.routes.length === 0) {
+ console.warn("No routes found");
+ return;
+ }
+ // [END maps_routes_markers_request_full]
+ // [START maps_routes_markers_style_maker]
+ // Alter style based on marker index.
+ function markerOptionsMaker(defaultOptions,
+ //@ts-ignore
+ waypointMarkerDetails) {
+ const { index, totalMarkers, leg } = waypointMarkerDetails;
+ // Style the origin waypoint.
+ if (index === 0) {
+ return {
+ ...defaultOptions,
+ map: innerMap,
+ content: new PinElement({
+ glyph: (index + 1).toString(),
+ glyphColor: 'white',
+ background: 'green',
+ borderColor: 'green',
+ }).element
+ };
+ }
+ // Style all intermediate waypoints.
+ if (!(index === 0 || index === totalMarkers - 1)) {
+ return {
+ ...defaultOptions,
+ map: innerMap,
+ content: new PinElement({
+ glyph: (index + 1).toString(),
+ glyphColor: 'white',
+ background: 'blue',
+ borderColor: 'blue',
+ }).element
+ };
+ }
+ // Style the destination waypoint.
+ if (index === totalMarkers - 1) {
+ return {
+ ...defaultOptions,
+ map: innerMap,
+ content: new PinElement({
+ glyph: (index + 1).toString(),
+ glyphColor: 'white',
+ background: 'red',
+ borderColor: 'red',
+ }).element
+ };
+ }
+ return { ...defaultOptions, map: innerMap };
+ }
+ const markers = await result.routes[0].createWaypointAdvancedMarkers(markerOptionsMaker);
+ // [END maps_routes_markers_style_maker]
+ // Fit the map to the route.
+ innerMap.fitBounds(result.routes[0].viewport);
+ innerMap.setHeading(270);
+ // Create polylines and add them to the map.
+ mapPolylines = result.routes[0].createPolylines();
+ mapPolylines.forEach((polyline) => polyline.setMap(innerMap));
+}
+initMap();
+// [END maps_routes_markers]
diff --git a/dist/samples/routes-markers/docs/index.ts b/dist/samples/routes-markers/docs/index.ts
new file mode 100644
index 00000000..75fd27e2
--- /dev/null
+++ b/dist/samples/routes-markers/docs/index.ts
@@ -0,0 +1,124 @@
+/*
+ * @license
+ * Copyright 2025 Google LLC. All Rights Reserved.
+ * SPDX-License-Identifier: Apache-2.0
+ */
+// [START maps_routes_markers]
+let mapPolylines: google.maps.Polyline[] = [];
+const mapElement = document.querySelector('gmp-map') as google.maps.MapElement;
+let innerMap;
+
+// Initialize and add the map.
+async function initMap() {
+ // Request the needed libraries.
+ await google.maps.importLibrary('maps');
+
+ innerMap = await mapElement.innerMap;
+ innerMap.setOptions({
+ mapTypeControl: false,
+ mapId: 'DEMO_MAP_ID',
+ });
+
+ // Call the function after the map is loaded.
+ google.maps.event.addListenerOnce(innerMap, 'idle', () => {
+ getDirections();
+ });
+}
+
+async function getDirections() {
+ //@ts-ignore
+ // Request the needed libraries.
+ const [{ Route }, { PinElement }] = await Promise.all([
+ google.maps.importLibrary('routes'),
+ google.maps.importLibrary('marker'),
+ ]);
+
+ // [START maps_routes_markers_request_full]
+ // [START maps_routes_markers_request]
+ // Define routes request with an intermediate stop.
+ const request = {
+ origin: 'Parking lot, Christmas Tree Point Rd, San Francisco, CA 94131',
+ destination: '100 Spinnaker Dr, Sausalito, CA 94965', // We're having a yummy lunch!
+ intermediates: [{ location: '300 Finley Rd San Francisco, CA 94129' }], // But first, we golf!
+ travelMode: 'DRIVING',
+ fields: ['path', 'legs', 'viewport'],
+ };
+ // [END maps_routes_markers_request]
+
+ // Call computeRoutes to get the directions.
+ const result = await Route.computeRoutes(request);
+ if (!result.routes || result.routes.length === 0) {
+ console.warn("No routes found");
+ return;
+ }
+ // [END maps_routes_markers_request_full]
+
+ // [START maps_routes_markers_style_maker]
+ // Alter style based on marker index.
+ function markerOptionsMaker(
+ defaultOptions: google.maps.marker.AdvancedMarkerElementOptions,
+ //@ts-ignore
+ waypointMarkerDetails: google.maps.routes.WaypointMarkerDetails
+ ) {
+ const { index, totalMarkers, leg } = waypointMarkerDetails;
+
+ // Style the origin waypoint.
+ if (index === 0) {
+ return {
+ ...defaultOptions,
+ map: innerMap,
+ content: new PinElement({
+ glyph: (index + 1).toString(),
+ glyphColor: 'white',
+ background: 'green',
+ borderColor: 'green',
+ }).element
+ }
+ }
+
+ // Style all intermediate waypoints.
+ if (!(index === 0 || index === totalMarkers - 1)) {
+ return {
+ ...defaultOptions,
+ map: innerMap,
+ content: new PinElement({
+ glyph: (index + 1).toString(),
+ glyphColor: 'white',
+ background: 'blue',
+ borderColor: 'blue',
+ }).element
+ }
+ }
+
+ // Style the destination waypoint.
+ if (index === totalMarkers - 1) {
+ return {
+ ...defaultOptions,
+ map: innerMap,
+ content: new PinElement({
+ glyph: (index + 1).toString(),
+ glyphColor: 'white',
+ background: 'red',
+ borderColor: 'red',
+ }).element
+ }
+ }
+
+ return { ...defaultOptions, map: innerMap };
+ }
+
+ const markers = await result.routes[0].createWaypointAdvancedMarkers(markerOptionsMaker);
+ // [END maps_routes_markers_style_maker]
+
+
+ // Fit the map to the route.
+ innerMap.fitBounds(result.routes[0].viewport);
+ innerMap.setHeading(270);
+
+ // Create polylines and add them to the map.
+ mapPolylines = result.routes[0].createPolylines();
+ mapPolylines.forEach((polyline) => polyline.setMap(innerMap));
+}
+
+initMap();
+// [END maps_routes_markers]
diff --git a/dist/samples/routes-markers/docs/style.css b/dist/samples/routes-markers/docs/style.css
new file mode 100644
index 00000000..14e92720
--- /dev/null
+++ b/dist/samples/routes-markers/docs/style.css
@@ -0,0 +1,24 @@
+/*
+ * @license
+ * Copyright 2025 Google LLC. All Rights Reserved.
+ * SPDX-License-Identifier: Apache-2.0
+ */
+/* [START maps_routes_markers] */
+/*
+ * Always set the map height explicitly to define the size of the div element
+ * that contains the map.
+ */
+#map {
+ height: 100%;
+}
+
+/*
+ * Optional: Makes the sample page fill the window.
+ */
+html,
+body {
+ height: 100%;
+ margin: 0;
+ padding: 0;
+}
+/* [END maps_routes_markers] */
diff --git a/dist/samples/routes-markers/jsfiddle/demo.css b/dist/samples/routes-markers/jsfiddle/demo.css
new file mode 100644
index 00000000..88fcce2a
--- /dev/null
+++ b/dist/samples/routes-markers/jsfiddle/demo.css
@@ -0,0 +1,24 @@
+/*
+ * @license
+ * Copyright 2025 Google LLC. All Rights Reserved.
+ * SPDX-License-Identifier: Apache-2.0
+ */
+
+/*
+ * Always set the map height explicitly to define the size of the div element
+ * that contains the map.
+ */
+#map {
+ height: 100%;
+}
+
+/*
+ * Optional: Makes the sample page fill the window.
+ */
+html,
+body {
+ height: 100%;
+ margin: 0;
+ padding: 0;
+}
+
diff --git a/dist/samples/routes-markers/jsfiddle/demo.details b/dist/samples/routes-markers/jsfiddle/demo.details
new file mode 100644
index 00000000..04050a61
--- /dev/null
+++ b/dist/samples/routes-markers/jsfiddle/demo.details
@@ -0,0 +1,7 @@
+name: routes-markers
+authors:
+ - Geo Developer IX Documentation Team
+tags:
+ - google maps
+load_type: h
+description: Sample code supporting Google Maps Platform JavaScript API documentation.
diff --git a/dist/samples/routes-markers/jsfiddle/demo.html b/dist/samples/routes-markers/jsfiddle/demo.html
new file mode 100644
index 00000000..44deb7cc
--- /dev/null
+++ b/dist/samples/routes-markers/jsfiddle/demo.html
@@ -0,0 +1,21 @@
+
+
+
+
+
+ Get directions
+
+
+
+
+
+
+
+
+
+
diff --git a/dist/samples/routes-markers/jsfiddle/demo.js b/dist/samples/routes-markers/jsfiddle/demo.js
new file mode 100644
index 00000000..25af9845
--- /dev/null
+++ b/dist/samples/routes-markers/jsfiddle/demo.js
@@ -0,0 +1,107 @@
+"use strict";
+/*
+ * @license
+ * Copyright 2025 Google LLC. All Rights Reserved.
+ * SPDX-License-Identifier: Apache-2.0
+ */
+
+let mapPolylines = [];
+const mapElement = document.querySelector('gmp-map');
+let innerMap;
+// Initialize and add the map.
+async function initMap() {
+ // Request the needed libraries.
+ await google.maps.importLibrary('maps');
+ innerMap = await mapElement.innerMap;
+ innerMap.setOptions({
+ mapTypeControl: false,
+ mapId: 'DEMO_MAP_ID',
+ });
+ // Call the function after the map is loaded.
+ google.maps.event.addListenerOnce(innerMap, 'idle', () => {
+ getDirections();
+ });
+}
+async function getDirections() {
+ //@ts-ignore
+ // Request the needed libraries.
+ const [{ Route }, { PinElement }] = await Promise.all([
+ google.maps.importLibrary('routes'),
+ google.maps.importLibrary('marker'),
+ ]);
+
+
+ // Define routes request with an intermediate stop.
+ const request = {
+ origin: 'Parking lot, Christmas Tree Point Rd, San Francisco, CA 94131',
+ destination: '100 Spinnaker Dr, Sausalito, CA 94965', // We're having a yummy lunch!
+ intermediates: [{ location: '300 Finley Rd San Francisco, CA 94129' }], // But first, we golf!
+ travelMode: 'DRIVING',
+ fields: ['path', 'legs', 'viewport'],
+ };
+
+ // Call computeRoutes to get the directions.
+ const result = await Route.computeRoutes(request);
+ if (!result.routes || result.routes.length === 0) {
+ console.warn("No routes found");
+ return;
+ }
+
+
+ // Alter style based on marker index.
+ function markerOptionsMaker(defaultOptions,
+ //@ts-ignore
+ waypointMarkerDetails) {
+ const { index, totalMarkers, leg } = waypointMarkerDetails;
+ // Style the origin waypoint.
+ if (index === 0) {
+ return {
+ ...defaultOptions,
+ map: innerMap,
+ content: new PinElement({
+ glyph: (index + 1).toString(),
+ glyphColor: 'white',
+ background: 'green',
+ borderColor: 'green',
+ }).element
+ };
+ }
+ // Style all intermediate waypoints.
+ if (!(index === 0 || index === totalMarkers - 1)) {
+ return {
+ ...defaultOptions,
+ map: innerMap,
+ content: new PinElement({
+ glyph: (index + 1).toString(),
+ glyphColor: 'white',
+ background: 'blue',
+ borderColor: 'blue',
+ }).element
+ };
+ }
+ // Style the destination waypoint.
+ if (index === totalMarkers - 1) {
+ return {
+ ...defaultOptions,
+ map: innerMap,
+ content: new PinElement({
+ glyph: (index + 1).toString(),
+ glyphColor: 'white',
+ background: 'red',
+ borderColor: 'red',
+ }).element
+ };
+ }
+ return { ...defaultOptions, map: innerMap };
+ }
+ const markers = await result.routes[0].createWaypointAdvancedMarkers(markerOptionsMaker);
+
+ // Fit the map to the route.
+ innerMap.fitBounds(result.routes[0].viewport);
+ innerMap.setHeading(270);
+ // Create polylines and add them to the map.
+ mapPolylines = result.routes[0].createPolylines();
+ mapPolylines.forEach((polyline) => polyline.setMap(innerMap));
+}
+initMap();
+
diff --git a/index.html b/index.html
index 32a03d1d..54a4c17e 100644
--- a/index.html
+++ b/index.html
@@ -66,6 +66,7 @@ Maps JSAPI Samples
routes-get-alternatives
routes-get-directions
routes-get-directions-panel
+ routes-markers
routes-route-matrix
test-example
ui-kit-customization
diff --git a/package-lock.json b/package-lock.json
index 854b20f0..0d50f0be 100644
--- a/package-lock.json
+++ b/package-lock.json
@@ -1416,6 +1416,10 @@
"resolved": "samples/routes-get-directions-panel",
"link": true
},
+ "node_modules/@js-api-samples/routes-markers": {
+ "resolved": "samples/routes-markers",
+ "link": true
+ },
"node_modules/@js-api-samples/routes-route-matrix": {
"resolved": "samples/routes-route-matrix",
"link": true
@@ -9179,6 +9183,10 @@
"name": "@js-api-samples/routes-get-directions-panel",
"version": "1.0.0"
},
+ "samples/routes-markers": {
+ "name": "@js-api-samples/routes-markers",
+ "version": "1.0.0"
+ },
"samples/routes-route-matrix": {
"name": "@js-api-samples/routes-route-matrix",
"version": "1.0.0"