<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Vedant Popli on Medium]]></title>
        <description><![CDATA[Stories by Vedant Popli on Medium]]></description>
        <link>https://medium.com/@vedant.popli?source=rss-3cdc69b5bbb5------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*g0D0UxsXC1cVkRSZ</url>
            <title>Stories by Vedant Popli on Medium</title>
            <link>https://medium.com/@vedant.popli?source=rss-3cdc69b5bbb5------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sun, 06 Dec 2026 02:06:45 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@vedant.popli/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[A Complete Guide to Using Google Maps in Angular 19 with @angular/google-maps]]></title>
            <link>https://medium.com/@vedant.popli/a-complete-guide-to-using-google-maps-in-angular-19-with-angular-google-maps-b53e012e8f9f?source=rss-3cdc69b5bbb5------2</link>
            <guid isPermaLink="false">https://medium.com/p/b53e012e8f9f</guid>
            <category><![CDATA[web-development]]></category>
            <category><![CDATA[angular]]></category>
            <category><![CDATA[typescript]]></category>
            <category><![CDATA[angular-google-map]]></category>
            <category><![CDATA[google-maps]]></category>
            <dc:creator><![CDATA[Vedant Popli]]></dc:creator>
            <pubDate>Wed, 10 Dec 2025 13:25:04 GMT</pubDate>
            <atom:updated>2025-12-10T13:25:04.172Z</atom:updated>
            <content:encoded><![CDATA[<h3>A Complete Guide to Use Google Maps in Angular 19 with @angular/google-maps</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*tW_YGYmFxA9Rw9KZBN2RbA.png" /></figure><p>When I first tried using @angular/google-maps, things weren’t very clear. That’s why I’ve put together this guide to help you set it up easily without confusion.</p><h3>Objective</h3><p>In this guide we’ll go step-by-step, covering how to:</p><ul><li>Add your Google Maps API key safely (without hardcoding it in your source)</li><li>Display routes using polylines</li><li>Create marker clusters for crowded maps</li><li>Draw circle areas and other overlays</li><li>Animate moving marker along a route</li><li>Show info windows for markers</li><li>Use custom images and change marker colors</li></ul><h3>My Project Setup</h3><p>In my project, I’m using <strong>Angular 19</strong> along with the @angular/google-maps package (<strong>v19.2.19</strong>). I’m also using <strong>TypeScript 5.8.3</strong>, <strong>RxJS 7.8.1</strong>, and <strong>Zone.js 0.15.1</strong>.</p><h3>Using @angular/google-maps</h3><h4><strong>1. Install the Google Maps package</strong></h4><p>Run the following command in your Angular project:</p><pre>npm i @angular/google-maps@19</pre><h4><strong>2. Create a Map Loader Service</strong></h4><p>This service will dynamically load the Google Maps JavaScript API and ensure it’s loaded only once across the app.</p><p><strong>map-loader-service.service.ts</strong></p><pre>import { Injectable } from &#39;@angular/core&#39;;<br>import { API_KEY } from &#39;../../environments/environment&#39;; // add Google Map API key in environment file<br><br>@Injectable({ providedIn: &#39;root&#39; })<br>export class MapLoaderService {<br>  private isLoaded = false;<br><br>  load(): Promise&lt;void&gt; {<br>    if (this.isLoaded) return Promise.resolve();<br><br>    return new Promise((resolve, reject) =&gt; {<br>      const script = document.createElement(&#39;script&#39;);<br>      const params = new URLSearchParams({<br>        key: API_KEY, // set to &#39;&#39; if API key not available yet<br>        v: &#39;beta&#39;,<br>        libraries: &#39;marker&#39;,<br>        callback: &#39;initMap&#39;<br>      });<br><br>      script.src = `https://maps.googleapis.com/maps/api/js?${params.toString()}`;<br>      script.async = true;<br>      script.defer = true;<br><br>      (window as any).initMap = () =&gt; resolve(undefined);<br><br>      script.onerror = () =&gt; reject(new Error(&#39;Failed to load Google Maps&#39;));<br>      document.head.appendChild(script);<br>    }).then(() =&gt; {<br>      this.isLoaded = true;<br>    });<br>  }<br>}</pre><h4><strong>3. Inject the service in your component</strong></h4><p><strong>app.component.ts</strong></p><pre>import { Component, OnInit, inject } from &#39;@angular/core&#39;;<br>import { GoogleMapsModule } from &#39;@angular/google-maps&#39;;<br>import { CommonModule } from &#39;@angular/common&#39;;<br>import { MapLoaderService } from &#39;./services/map-loader-service.service&#39;;<br><br>@Component({<br>  selector: &#39;app-root&#39;,<br>  standalone: true,<br>  imports: [GoogleMapsModule, CommonModule],<br>  templateUrl: &#39;./app.component.html&#39;,<br>  styleUrl: &#39;./app.component.scss&#39;<br>})<br>export class AppComponent implements OnInit {<br><br>  // This flag prevents Angular from rendering the &lt;google-map&gt;<br>  // before the Google Maps JS API is fully loaded.<br>  // Without this, you&#39;ll get &quot;google is not defined&quot; or blank maps.<br>  isMapLoaded = false;<br><br>  private mapLoaderService = inject(MapLoaderService);<br><br>  // Initial map settings<br>  mapOptions = {<br>    center: { lat: 19.098272, lng: 72.874928 },<br>    zoom: 13<br>  };<br><br>  ngOnInit(): void {<br><br>    // Load the Google Maps script first.<br>    // Then allow the map to render.<br>    this.mapLoaderService.load()<br>      .then(() =&gt; {<br>        this.isMapLoaded = true; // Map can now safely render<br>        console.log(&#39;Google Maps loaded successfully&#39;);<br>      })<br>      .catch(err =&gt; {<br>        console.error(&#39;Failed to load Google Maps:&#39;, err);<br>      });<br>  }<br>}<br></pre><blockquote>Full list of map options:</blockquote><blockquote><a href="https://developers.google.com/maps/documentation/javascript/reference/map#MapOptions">https://developers.google.com/maps/documentation/javascript/reference/map#MapOption</a>s</blockquote><h4><strong>4. Add the map in your template</strong></h4><pre>&lt;!--<br>  Use *ngIf with isMapLoaded to make sure the map renders<br>  ONLY after the Google Maps script has finished loading.<br>  This avoids initialization errors and blank map screens.<br>--&gt;<br>&lt;google-map<br>  *ngIf=&quot;isMapLoaded&quot;<br>  [options]=&quot;mapOptions&quot;<br>  width=&quot;100vw&quot;<br>  height=&quot;100vh&quot;<br>  mapId=&quot;myMap&quot;<br>&gt;<br>&lt;/google-map&gt;</pre><p>That’s all you need for the basic Google Maps setup in Angular.<br>From here, we can start adding features like <strong>markers, routes, clustering, circles, custom icons, and moving objects</strong>.</p><h3><strong>Playing with Markers in @angular/google-maps</strong></h3><p>Markers are one of the most common elements used on Google Maps. They help display a specific point on the map or a list of GPS locations. Below are different ways you can work with markers using the @angular/google-maps library.</p><h4><strong>1. Adding a Single Marker</strong></h4><p><em>Step 1 — Define a marker position</em></p><pre>import { Component, OnInit, inject } from &#39;@angular/core&#39;;<br>import { GoogleMapsModule } from &#39;@angular/google-maps&#39;;<br>import { CommonModule } from &#39;@angular/common&#39;;<br>import { MapLoaderService } from &#39;./services/map-loader-service.service&#39;;<br><br>@Component({<br>  selector: &#39;app-root&#39;,<br>  imports: [GoogleMapsModule, CommonModule],<br>  templateUrl: &#39;./app.component.html&#39;,<br>  styleUrl: &#39;./app.component.scss&#39;,<br>})<br>export class AppComponent implements OnInit {<br>  isMapLoaded = false;<br>  private mapLoaderService = inject(MapLoaderService);<br><br>  // Single marker position<br>  markerPosition: google.maps.LatLngLiteral = {<br>    lat: 19.098272,<br>    lng: 72.874928,<br>  };<br><br>  mapOptions = {<br>    center: { lat: 19.118, lng: 72.8673 },<br>    zoom: 16<br>  };<br><br>  ngOnInit(): void {<br>    this.mapLoaderService<br>      .load()<br>      .then(() =&gt; {<br>        this.isMapLoaded = true;<br>        this.mapOptions.center = this.markerPosition; // center on marker<br>      })<br>      .catch((err) =&gt; console.error(&#39;Failed to load Google Maps:&#39;, err));<br>  }<br>}</pre><p><em>Step 2 — Display the marker</em></p><pre>&lt;google-map<br>  *ngIf=&quot;isMapLoaded&quot;<br>  [options]=&quot;mapOptions&quot;<br>  width=&quot;100vw&quot;<br>  height=&quot;100vh&quot;<br>  mapId=&quot;myMap&quot;&gt;<br><br>  &lt;map-advanced-marker [position]=&quot;markerPosition&quot;&gt;&lt;/map-advanced-marker&gt;<br><br>&lt;/google-map&gt;</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*sebvdoaklCJ9yH3tPm8CHw.png" /><figcaption>Implimentation of showing marker in map</figcaption></figure><h4><strong>2. Adding Multiple Markers</strong></h4><p><em>Step 1 — Create an array of positions</em></p><pre>popularLandmarkPositions: google.maps.LatLngLiteral[] = [<br>  { lat: 19.113645, lng: 72.869736 }, // Andheri Station<br>  { lat: 19.119738, lng: 72.873558 }, // Andheri Subway<br>  { lat: 19.126453, lng: 72.83238 },  // Juhu Beach Entry<br>  { lat: 19.131064, lng: 72.815773 }, // Juhu Beach Central<br>  { lat: 19.134471, lng: 72.823879 }, // Versova Link Road<br>  { lat: 19.138293, lng: 72.823725 }, // Versova Metro<br>];</pre><p><em>Step 2 — Center map on the first marker</em></p><pre>ngOnInit(): void {<br>  this.mapLoaderService.load()<br>    .then(() =&gt; {<br>      this.isMapLoaded = true;<br>      this.mapOptions.center = this.popularLandmarkPositions[0];<br>    })<br>    .catch(err =&gt; console.error(&#39;Failed to load Google Maps:&#39;, err));<br>}</pre><p><em>Step 3 — Loop through the list and add markers</em></p><pre>&lt;google-map<br>  *ngIf=&quot;isMapLoaded&quot;<br>  [options]=&quot;mapOptions&quot;<br>  width=&quot;100vw&quot;<br>  height=&quot;100vh&quot;<br>  mapId=&quot;myMap&quot;&gt;<br><br>  @for (position of popularLandmarkPositions; track $index) {<br>    &lt;map-advanced-marker [position]=&quot;position&quot;&gt;&lt;/map-advanced-marker&gt;<br>  }<br><br>&lt;/google-map&gt;</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*c2vN17j3fzlMIuErBn8Sfw.png" /><figcaption>Implimentation of showing multiple markers in maps</figcaption></figure><h4><strong>3. Using Custom marker icon</strong></h4><p>Sometimes a simple pin isn’t enough. You might wA Complete Guide to Using Google Maps in Angular 19 with @angular/google-mapsant to use a custom icon (e.g., a monument symbol, a vehicle icon, a logo, etc.).</p><p><em>Step 1 — Define an icon config</em></p><pre>markerIcon = {<br>  url: &#39;assets/images/monument.svg&#39;,<br>  scaledSize: {<br>    width: 40,<br>    height: 40,<br>  },<br>};</pre><p><em>Step 2 — Render the custom icon inside the marker</em></p><pre>&lt;google-map<br>  *ngIf=&quot;isMapLoaded&quot;<br>  [options]=&quot;mapOptions&quot;<br>  width=&quot;100vw&quot;<br>  height=&quot;100vh&quot;<br>  mapId=&quot;myMap&quot;<br>&gt;<br>  @for (position of popularLandmarkPositions; track $index) {<br>    &lt;div #markerDom&gt;<br>      &lt;img<br>        style=&quot;background-color: rgb(79, 161, 255); border-radius: 50%&quot;<br>        [src]=&quot;markerIcon.url&quot;<br>        [width]=&quot;markerIcon.scaledSize.width&quot;<br>        [height]=&quot;markerIcon.scaledSize.height&quot;<br>        alt=&quot;stop marker&quot;<br>      /&gt;<br>    &lt;/div&gt;<br>    &lt;map-advanced-marker<br>      [position]=&quot;position&quot;<br>      [content]=&quot;markerDom&quot;<br>    &gt;&lt;/map-advanced-marker&gt;<br>  }<br>&lt;/google-map&gt;</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*sF0SA9gA9JPZ49GVR7Ss9A.png" /><figcaption>Using custom markers</figcaption></figure><h3>Displaying a Polyline on the Map</h3><p>To draw a polyline (a route) on Google Maps, you need two things:</p><ol><li><strong>An array of latitude/longitude coordinates</strong></li><li><strong>Optional polyline options</strong> (color, weight, opacity, etc.)</li></ol><p>Below is an example that draws a route on the map along with a Start and End marker.</p><h4><strong>1. Component Setup (app.component.ts)</strong></h4><pre>import { Component, OnInit, inject } from &#39;@angular/core&#39;;<br>import { GoogleMapsModule } from &#39;@angular/google-maps&#39;;<br>import { CommonModule } from &#39;@angular/common&#39;;<br>import { MapLoaderService } from &#39;./services/map-loader-service.service&#39;;<br><br>@Component({<br>  selector: &#39;app-root&#39;,<br>  imports: [GoogleMapsModule, CommonModule],<br>  templateUrl: &#39;./app.component.html&#39;,<br>  styleUrl: &#39;./app.component.scss&#39;,<br>})<br>export class AppComponent implements OnInit {<br><br>  isMapLoaded = false;<br><br>  // Route coordinates<br>  coordinates = [<br>    { lat: 19.062815, lng: 72.8416 },<br>    { lat: 19.062803, lng: 72.841484 },<br>    { lat: 19.062756, lng: 72.84146 },<br>    // ... I had 80 items in this list<br>  ];<br><br>  // Start and End markers<br>  startPoint = this.coordinates[0];<br>  endPoint = this.coordinates[this.coordinates.length - 1];<br><br>  // Styling for the polyline<br>  polylineOptions = {<br>    strokeColor: &#39;#0400ffff&#39;,<br>    strokeOpacity: 1.0,<br>    strokeWeight: 3,<br>  };<br><br>  private mapLoaderService = inject(MapLoaderService);<br><br>  mapOptions = {<br>    center: { lat: 19.098272, lng: 72.874928 },<br>    zoom: 14<br>  };<br><br>  ngOnInit(): void {<br>    this.mapLoaderService.load()<br>      .then(() =&gt; {<br>        this.isMapLoaded = true;<br><br>        // Center map on the start point<br>        this.mapOptions.center = this.startPoint;<br>        console.log(&#39;Google Maps loaded successfully&#39;);<br>      })<br>      .catch(err =&gt; console.error(&#39;Failed to load Google Maps:&#39;, err));<br>  }<br>}</pre><h4><strong>2. Displaying the Polyline in the Template</strong></h4><p>This template displays:</p><ul><li>the map</li><li>the polyline</li><li>a custom Start marker</li><li>a custom End marker</li></ul><pre>&lt;google-map<br>  *ngIf=&quot;isMapLoaded&quot;<br>  [options]=&quot;mapOptions&quot;<br>  width=&quot;100vw&quot;<br>  height=&quot;100vh&quot;<br>  mapId=&quot;myMap&quot;<br>&gt;<br>  &lt;map-polyline [path]=&quot;coordinates&quot; [options]=&quot;polylineOptions&quot;&gt;&lt;/map-polyline&gt;<br><br>  &lt;map-advanced-marker [position]=&quot;startPoint&quot; [content]=&quot;startPointMarker&quot;&gt;&lt;/map-advanced-marker&gt;<br><br>  &lt;map-advanced-marker [position]=&quot;endPoint&quot; [content]=&quot;endPointMarker&quot;&gt;&lt;/map-advanced-marker&gt;<br><br>  &lt;div #startPointMarker&gt;<br>    &lt;span style=&quot;background-color: rgb(70, 221, 0);border-radius: 50%;padding: 6px 10px;color: #fff;&quot;&gt;<br>      Start<br>    &lt;/span&gt;<br>  &lt;/div&gt;<br><br>  &lt;div #endPointMarker&gt;<br>    &lt;span style=&quot;background-color: rgb(255, 79, 79);border-radius: 50%;padding: 6px 10px;color: #fff;&quot;&gt;<br>      End<br>    &lt;/span&gt;<br>  &lt;/div&gt;<br>&lt;/google-map&gt;</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*fx-taOS6koL8ggL6x2eOmA.png" /><figcaption>Route polyline with start point and end point.</figcaption></figure><h4><strong>Drawing Multiple Routes</strong></h4><p>To display more than one route on the same map:</p><ul><li>Create multiple <strong>coordinate arrays</strong></li><li>Create multiple <strong>polyline options</strong> (if you want different colors)</li><li>Add multiple &lt;map-polyline&gt; elements</li></ul><p><strong>Example:</strong></p><pre>&lt;map-polyline [path]=&quot;route1&quot;&gt;&lt;/map-polyline&gt;<br>&lt;map-polyline [path]=&quot;route2&quot; [options]=&quot;{ strokeColor: &#39;red&#39; }&quot;&gt;&lt;/map-polyline&gt;</pre><h3>Displaying an Information Window on the Map</h3><p>Information windows help show useful details when a user clicks a marker, such as the place name, description, area, timing, entry fee, and more.</p><p>In the @angular/google-maps library, you can define <strong>only one</strong> &lt;map-info-window&gt; in the template. But you can <strong>reuse that single instance</strong> with any marker by opening it with a reference on click.</p><h4><strong>1. Component Setup (app.component.ts)</strong></h4><p>In this example, we:</p><ul><li>Create a list of popular Mumbai places</li><li>Reuse one InfoWindow for all markers</li><li>Display the InfoWindow when a marker is clicked</li></ul><pre>import { Component, OnInit, ViewChild, inject } from &#39;@angular/core&#39;;<br>import { GoogleMapsModule, MapInfoWindow } from &#39;@angular/google-maps&#39;;<br>import { CommonModule } from &#39;@angular/common&#39;;<br>import { MapLoaderService } from &#39;./services/map-loader-service.service&#39;;<br><br>@Component({<br>  selector: &#39;app-root&#39;,<br>  imports: [GoogleMapsModule, CommonModule],<br>  templateUrl: &#39;./app.component.html&#39;,<br>  styleUrl: &#39;./app.component.scss&#39;,<br>})<br>export class AppComponent implements OnInit {<br><br>  isMapLoaded = false;<br><br>  // Store details of the marker the user clicks<br>  selectedPlace: any = {};<br><br>  // Only one info window instance is allowed in @angular/google-maps<br>  @ViewChild(MapInfoWindow) infoWindow!: MapInfoWindow;<br><br>  // Popular places in Mumbai<br>  mumbaiPopularPlaces = [<br>    {<br>      name: &#39;Haji Ali Dargah&#39;,<br>      lat: 18.982721,<br>      lng: 72.808977,<br>      area: &#39;Worli&#39;,<br>      category: &#39;Shrine&#39;,<br>      description:<br>        &#39;Mosque located on a small islet accessible by causeway during low tide.&#39;,<br>      bestTime: &#39;Early Morning / Evening&#39;,<br>      entryFee: &#39;Free&#39;,<br>    },<br>    {<br>      name: &#39;Sanjay Gandhi National Park&#39;,<br>      lat: 19.214706,<br>      lng: 72.907388,<br>      area: &#39;Borivali&#39;,<br>      category: &#39;National Park&#39;,<br>      description:<br>        &#39;Large forest reserve famous for Kanheri Caves and wildlife.&#39;,<br>      bestTime: &#39;Morning&#39;,<br>      entryFee: &#39;₹85&#39;,<br>    },<br>  ];<br><br>  private mapLoaderService = inject(MapLoaderService);<br><br>  mapOptions = {<br>    center: { lat: 19.098272, lng: 72.874928 },<br>    zoom: 11<br>  };<br><br>  ngOnInit(): void {<br>    this.mapLoaderService<br>      .load()<br>      .then(() =&gt; {<br>        this.isMapLoaded = true;<br>      })<br>      .catch((err) =&gt; console.error(&#39;Failed to load Google Maps:&#39;, err));<br>  }<br><br>  // Open info window for the selected marker<br>  showInfoWindow(markerRef: any, place: any) {<br>    this.selectedPlace = place;<br>    this.infoWindow.open(markerRef);<br>  }<br>}</pre><h4><strong>2. Template Setup (app.component.html)</strong></h4><p>This includes:</p><ul><li>Custom icon for the marker</li><li>A single reusable InfoWindow</li><li>Dynamic content bound to selectedPlace</li></ul><pre>&lt;google-map<br>  *ngIf=&quot;isMapLoaded&quot;<br>  [options]=&quot;mapOptions&quot;<br>  width=&quot;100vw&quot;<br>  height=&quot;100vh&quot;<br>  mapId=&quot;myMap&quot;<br>&gt;<br>  @for(place of mumbaiPopularPlaces; track $index) {<br>    &lt;map-advanced-marker<br>      #markerRef2=&quot;mapAdvancedMarker&quot;<br>      [position]=&quot;place&quot;<br>      [content]=&quot;monumentMarker&quot;<br>      (mapClick)=&quot;showInfoWindow(markerRef2, place)&quot;<br>    &gt;&lt;/map-advanced-marker&gt;<br>  <br>    &lt;div #monumentMarker&gt;<br>      &lt;img<br>        src=&quot;../assets/images/monument.svg&quot;<br>        alt=&quot;monument&quot;<br>        style=&quot;width: 32px; height: 32px;background-color: cornflowerblue; border-radius: 50%;&quot;/&gt;<br>    &lt;/div&gt;<br>  }<br><br>  &lt;map-info-window #infoWindow&gt;<br>    &lt;div&gt;<br>      &lt;div class=&quot;&quot;&gt;<br>        &lt;div&gt;Name : {{ selectedPlace.name }}&lt;/div&gt;<br>        &lt;div&gt;Area : {{ selectedPlace.area }}&lt;/div&gt;<br>        &lt;div&gt;Entry Fee : {{ selectedPlace.entryFee }}&lt;/div&gt;<br>        &lt;div&gt;Best Time : {{ selectedPlace.bestTime }}&lt;/div&gt;<br>        &lt;div&gt;Description : {{ selectedPlace.description }}&lt;/div&gt;<br>      &lt;/div&gt;<br>    &lt;/div&gt;<br>  &lt;/map-info-window&gt;<br>&lt;/google-map&gt;</pre><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2F_ykxbI8OrIE%3Ffeature%3Doembed&amp;display_name=YouTube&amp;url=https%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3D_ykxbI8OrIE&amp;image=https%3A%2F%2Fi.ytimg.com%2Fvi%2F_ykxbI8OrIE%2Fhqdefault.jpg&amp;type=text%2Fhtml&amp;schema=youtube" width="640" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/a1ca97e83169902cc9ce0845ceaedc2c/href">https://medium.com/media/a1ca97e83169902cc9ce0845ceaedc2c/href</a></iframe><blockquote>Based on my testing and research, the @angular/google-maps library supports only <strong>one</strong> &lt;map-info-window&gt; instance at a time.<br>In older libraries like <strong>AGM</strong>, it was possible to open multiple InfoWindows on the map simultaneously.<br>If there’s another way to achieve multiple active InfoWindows with this library, please feel free to correct me.</blockquote><h3>Displaying a Circle Area Over the Map</h3><p>Displaying a circle on a Google Map is very simple with @angular/google-maps.<br>Circles are useful when you want to highlight:</p><ul><li>a coverage zone</li><li>an area around a marker</li></ul><p>The example below shows how to draw a circle and detect when it is dragged.</p><h4><strong>1. Component Setup (app.component.ts)</strong></h4><pre>import { Component, OnInit, inject } from &#39;@angular/core&#39;;<br>import { GoogleMapsModule } from &#39;@angular/google-maps&#39;;<br>import { CommonModule } from &#39;@angular/common&#39;;<br>import { MapLoaderService } from &#39;./services/map-loader-service.service&#39;;<br><br>@Component({<br>  selector: &#39;app-root&#39;,<br>  imports: [GoogleMapsModule, CommonModule],<br>  templateUrl: &#39;./app.component.html&#39;,<br>  styleUrl: &#39;./app.component.scss&#39;,<br>})<br>export class AppComponent implements OnInit {<br><br>  // Prevents rendering the map before Google Maps script loads<br>  isMapLoaded = false;<br><br>  private mapLoaderService = inject(MapLoaderService);<br><br>  // Map configuration<br>  mapOptions = {<br>    center: { lat: 19.098272, lng: 72.874928 },<br>    zoom: 11<br>  };<br><br>  // Circle styling and behavior<br>  circleOptions = {<br>    center: { lat: 19.098272, lng: 72.874928 },<br>    radius: 1000,          // in meters<br>    fillColor: &#39;#FF0000&#39;,<br>    fillOpacity: 0.35,<br>    strokeColor: &#39;#FF0000&#39;,<br>    strokeOpacity: 1,<br>    strokeWeight: 2,<br>    draggable: true,       // Allows dragging the circle<br>  };<br><br>  ngOnInit(): void {<br>    this.mapLoaderService.load()<br>      .then(() =&gt; {<br>        this.isMapLoaded = true;<br>      })<br>      .catch(err =&gt;<br>        console.error(&#39;Failed to load Google Maps:&#39;, err)<br>      );<br>  }<br><br>  // Triggered when the user finishes dragging the circle<br>  onCircleDragged(circle: any) {<br>    console.log(&#39;Circle dragged:&#39;, circle);<br>  }<br>}</pre><h4><strong>2. Template Setup (app.component.html)</strong></h4><pre>&lt;google-map<br>  *ngIf=&quot;isMapLoaded&quot;<br>  [options]=&quot;mapOptions&quot;<br>  width=&quot;100vw&quot;<br>  height=&quot;100vh&quot;<br>  mapId=&quot;myMap&quot;<br>&gt;<br><br>  &lt;!-- Display circle on the map --&gt;<br>  &lt;map-circle<br>    [options]=&quot;circleOptions&quot;<br>    (circleDragend)=&quot;onCircleDragged($event)&quot;&gt;<br>  &lt;/map-circle&gt;<br><br>&lt;/google-map&gt;</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*EdE77nBDv4JItD4VyOtVKw.png" /><figcaption>Example of using circle area usage</figcaption></figure><h3>Adding Marker Clustering to the Map</h3><p>When you display many markers close to each other, the map can become cluttered and difficult to read.<br>Google Maps provides <strong>Marker Clustering</strong>, which groups nearby markers into a single cluster icon.<br> This improves both <strong>readability</strong> and <strong>performance</strong>, especially when dealing with large datasets.</p><h4><strong>1. Add MarkerClusterer Script in </strong><strong>index.html</strong></h4><p>Before using clusters, you need to include the MarkerClusterer script:</p><pre>&lt;script src=&quot;https://unpkg.com/@googlemaps/markerclusterer/dist/index.min.js&quot;&gt;&lt;/script&gt;</pre><h4><strong>2. Component Setup (app.component.ts)</strong></h4><p>In this example, we:</p><ul><li>Use a large set of coordinates from Mumbai</li><li>Apply custom cluster styles based on marker count</li><li>Configure cluster behavior (grid size, minimum cluster size, etc.)</li></ul><pre>import { Component, OnInit, inject } from &#39;@angular/core&#39;;<br>import {<br>  GoogleMapsModule,<br>  MapMarkerClusterer,<br>  Renderer,<br>} from &#39;@angular/google-maps&#39;;<br>import { CommonModule } from &#39;@angular/common&#39;;<br>import { MapLoaderService } from &#39;./services/map-loader-service.service&#39;;<br><br>@Component({<br>  selector: &#39;app-root&#39;,<br>  imports: [GoogleMapsModule, CommonModule, MapMarkerClusterer],<br>  templateUrl: &#39;./app.component.html&#39;,<br>  styleUrl: &#39;./app.component.scss&#39;,<br>})<br>export class AppComponent implements OnInit {<br><br>  // Prevents map from rendering before script is loaded<br>  isMapLoaded = false;<br><br>  private mapLoaderService = inject(MapLoaderService);<br><br><br>  // Test coordinates around Mumbai<br>  clusterTestCoordinates = [<br>    // — Andheri West &amp; Juhu —<br>    { lat: 19.11382, lng: 72.85194 },<br>    { lat: 19.11435, lng: 72.85316 },<br>    { lat: 19.11592, lng: 72.85147 },<br>    { lat: 19.11756, lng: 72.85284 },<br>    { lat: 19.11844, lng: 72.85012 },<br><br>    { lat: 19.09873, lng: 72.8449 },<br>    { lat: 19.10041, lng: 72.84321 },<br>    { lat: 19.10164, lng: 72.83611 },<br>    { lat: 19.10318, lng: 72.84233 },<br>    { lat: 19.09592, lng: 72.84761 },<br>    // ...<br>  ];<br><br>  // Map settings<br>  mapOptions = {<br>    center: { lat: 19.118, lng: 72.8673 },<br>    zoom: 16<br>  };<br><br>  // Custom cluster rendering (color + size based on marker count)<br>  customClusterRenderer: Renderer = {<br>    render: ({ count, position }) =&gt; {<br>      let color = &#39;#0080f7ff&#39;;<br>      let size = 36;<br><br>      if (count &gt;= 7) {<br>        color = &#39;#F59E0B&#39;;<br>        size = 42;<br>      }<br><br>      if (count &gt;= 15) {<br>        color = &#39;#EF4444&#39;;<br>        size = 46;<br>      }<br><br>      return new google.maps.Marker({<br>        position,<br>        icon: {<br>          path: google.maps.SymbolPath.CIRCLE,<br>          scale: size / 3,<br>          fillColor: color,<br>          fillOpacity: 0.85,<br>          strokeColor: &#39;#FFFFFF&#39;,<br>          strokeWeight: 2,<br>        },<br>        label: {<br>          text: String(count),<br>          color: &#39;white&#39;,<br>          fontSize: &#39;14px&#39;,<br>          fontWeight: &#39;700&#39;,<br>        },<br>        title: `Cluster of ${count} markers`,<br>        zIndex: 1000 + count,<br>      });<br>    },<br>  };<br><br>  ngOnInit(): void {<br>    this.mapLoaderService.load()<br>      .then(() =&gt; {<br>        this.isMapLoaded = true;<br>      })<br>      .catch(err =&gt; console.error(&#39;Failed to load Google Maps:&#39;, err));<br>  }<br>}</pre><h4><strong>3. Add Clustering in Template (app.component.html)</strong></h4><pre>&lt;google-map<br>  *ngIf=&quot;isMapLoaded&quot;<br>  [options]=&quot;mapOptions&quot;<br>  width=&quot;100vw&quot;<br>  height=&quot;100vh&quot;<br>  mapId=&quot;myMap&quot;<br>&gt;<br><br>  &lt;!-- Marker Clusterer --&gt;<br>  &lt;map-marker-clusterer [renderer]=&quot;customClusterRenderer&quot;&gt;<br>    @for (location of clusterTestCoordinates; track $index) {<br>      &lt;map-marker [position]=&quot;location&quot;&gt;&lt;/map-marker&gt;<br>    }<br>  &lt;/map-marker-clusterer&gt;<br><br>&lt;/google-map&gt;</pre><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2FseqXK-m0Ovw%3Ffeature%3Doembed&amp;display_name=YouTube&amp;url=https%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3DseqXK-m0Ovw&amp;image=https%3A%2F%2Fi.ytimg.com%2Fvi%2FseqXK-m0Ovw%2Fhqdefault.jpg&amp;type=text%2Fhtml&amp;schema=youtube" width="640" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/bb7486008ae486af0eec343f53457be7/href">https://medium.com/media/bb7486008ae486af0eec343f53457be7/href</a></iframe><h3><strong>Animating a Moving Object on a Google Map Route</strong></h3><p>Animating a marker along a polyline is one of the most common features in real-time tracking apps — such as live bus tracking, taxi movement, delivery drivers, or any moving object.</p><p>This example uses:</p><ul><li>A list of coordinates</li><li>A moving <strong>Advanced Marker</strong></li><li>A simple timer to animate the movement</li><li>Start and End markers</li><li>A polyline showing the full route</li></ul><h4><strong>1. Component Logic (app.component.ts)</strong></h4><pre>import { Component, OnInit, inject } from &#39;@angular/core&#39;;<br>import { GoogleMapsModule } from &#39;@angular/google-maps&#39;;<br>import { CommonModule } from &#39;@angular/common&#39;;<br>import { MapLoaderService } from &#39;./services/map-loader-service.service&#39;;<br><br>@Component({<br>  selector: &#39;app-root&#39;,<br>  imports: [GoogleMapsModule, CommonModule],<br>  templateUrl: &#39;./app.component.html&#39;,<br>  styleUrl: &#39;./app.component.scss&#39;,<br>})<br>export class AppComponent implements OnInit {<br><br>  isMapLoaded = false;<br>  private mapLoaderService = inject(MapLoaderService);<br><br>  // Complete route coordinates (Mumbai example)<br>  coordinates = [<br>    { lat: 19.062815, lng: 72.8416 },<br>    { lat: 19.062803, lng: 72.841484 },<br>    { lat: 19.062756, lng: 72.84146 },<br>    { lat: 19.062662, lng: 72.84145 },<br>    { lat: 19.062416, lng: 72.84145 },<br>    { lat: 19.06199, lng: 72.841446 },<br>    { lat: 19.061539, lng: 72.84143 },<br>    { lat: 19.061106, lng: 72.84142 },<br>    ...<br>    { lat: 19.05453, lng: 72.846214 },<br>    { lat: 19.054453, lng: 72.84622 },<br>  ];<br><br>  // Start and End markers<br>  startPoint = this.coordinates[0];<br>  endPoint = this.coordinates[this.coordinates.length - 1];<br><br>  // Animation controls<br>  currentVehicleIndex = 0;<br>  vehiclePosition = this.coordinates[0];<br>  movementTimer: any;<br><br>  // Start moving the vehicle along the route<br>  startMovement() {<br>    this.movementTimer = setInterval(() =&gt; {<br>      this.currentVehicleIndex++;<br><br>      // If we reach the end of the route, stop animation<br>      if (this.currentVehicleIndex &gt;= this.coordinates.length) {<br>        this.stopMovement();<br>        return;<br>      }<br><br>      this.vehiclePosition = this.coordinates[this.currentVehicleIndex];<br>    }, 500); // move every 0.5 seconds<br>  }<br><br>  stopMovement() {<br>    clearInterval(this.movementTimer);<br>  }<br><br>  // Map settings<br>  mapOptions = {<br>    center: { lat: 19.118, lng: 72.8673 },<br>    zoom: 16<br>  };<br><br>  ngOnInit(): void {<br>    this.mapLoaderService<br>      .load()<br>      .then(() =&gt; {<br>        this.isMapLoaded = true;<br><br>        // Center map on starting point of the route<br>        this.mapOptions.center = this.startPoint;<br><br>        // Begin animation<br>        this.startMovement();<br>      })<br>      .catch(err =&gt; console.error(&#39;Failed to load Google Maps:&#39;, err));<br>  }<br>}</pre><h4><strong>2. Template (app.component.html)</strong></h4><p>This template includes:</p><ul><li>A Start marker</li><li>An End marker</li><li>A Vehicle marker (updated dynamically)</li><li>A polyline showing the full route</li></ul><pre>&lt;google-map<br>  *ngIf=&quot;isMapLoaded&quot;<br>  [options]=&quot;mapOptions&quot;<br>  width=&quot;100vw&quot;<br>  height=&quot;100vh&quot;<br>  mapId=&quot;myMap&quot;&gt;<br><br>  &lt;!-- Start Marker --&gt;<br>  &lt;map-advanced-marker *ngIf=&quot;startPoint&quot; [position]=&quot;startPoint&quot; [content]=&quot;startTpl&quot;&gt;&lt;/map-advanced-marker&gt;<br>  &lt;ng-template #startTpl&gt;<br>    &lt;span style=&quot;background:#46dd00;border-radius:50%;padding:6px 10px;color:#fff;&quot;&gt;Start&lt;/span&gt;<br>  &lt;/ng-template&gt;<br><br>  &lt;!-- End Marker --&gt;<br>  &lt;map-advanced-marker *ngIf=&quot;endPoint&quot; [position]=&quot;endPoint&quot; [content]=&quot;endTpl&quot;&gt;&lt;/map-advanced-marker&gt;<br>  &lt;ng-template #endTpl&gt;<br>    &lt;span style=&quot;background:#ff4f4f;border-radius:50%;padding:6px 10px;color:#fff;&quot;&gt;End&lt;/span&gt;<br>  &lt;/ng-template&gt;<br><br>  &lt;!-- Moving Vehicle Marker --&gt;<br>  &lt;map-advanced-marker *ngIf=&quot;vehiclePosition&quot; [position]=&quot;vehiclePosition&quot; [content]=&quot;vehicleTpl&quot;&gt;&lt;/map-advanced-marker&gt;<br>  &lt;ng-template #vehicleTpl&gt;<br>    &lt;img src=&quot;assets/images/motorcycle.svg&quot; alt=&quot;Vehicle&quot;<br>         style=&quot;background:#75ccff;width:35px;height:35px;border-radius:50%;&quot; /&gt;<br>  &lt;/ng-template&gt;<br><br>  &lt;!-- Route Polyline --&gt;<br>  &lt;map-polyline [path]=&quot;coordinates&quot;&gt;&lt;/map-polyline&gt;<br><br>&lt;/google-map&gt;</pre><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2FthLODd7SWHw%3Ffeature%3Doembed&amp;display_name=YouTube&amp;url=https%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3DthLODd7SWHw&amp;image=https%3A%2F%2Fi.ytimg.com%2Fvi%2FthLODd7SWHw%2Fhqdefault.jpg&amp;type=text%2Fhtml&amp;schema=youtube" width="640" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/450d1c3c7e02c005f4312b30c3a8db50/href">https://medium.com/media/450d1c3c7e02c005f4312b30c3a8db50/href</a></iframe><h4>How the Animation Works</h4><ul><li>The route is a static array of coordinates.</li><li>A timer (setInterval) updates the vehicle&#39;s index every 500ms.</li><li>Each update changes the vehicle’s marker position.</li><li>The map automatically re-renders the marker smoothly.</li><li>When the last point is reached, the animation stops.</li></ul><p>This is the most straightforward way to animate a moving object using Angular Google Maps.</p><h4><strong>Few Important Things You Should Know</strong></h4><p>Before wrapping up, here are some important points that will help you avoid common issues while working with <strong>@angular/google-maps</strong>:</p><ol><li><strong>Google Maps API requires billing</strong><br>The map won’t load unless billing is enabled on your Google Cloud project.<br>Also make sure that <strong>Maps JavaScript API</strong> is enabled in the Google Cloud Console.</li><li><strong>Don’t hardcode your API Key<br></strong>Always keep your API key inside Angular environment files.</li><li><strong>A &lt;google-map&gt; must have width and height<br></strong>If width and height are missing, the map will appear <strong>blank</strong>.</li></ol><p>Thats all for now. If you have any issue, suggestion contact me at vedantpopli.work@gmail.com.</p><h4><strong>References</strong></h4><p><a href="https://github.com/angular/components/blob/main/src/google-maps/README.md">https://github.com/angular/components/blob/main/src/google-maps/README.md</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=b53e012e8f9f" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>