Warning: Google Map API alert for outdated Marker Class

Working on an application using the Google Maps TypeScript API, I came across a warning message when launching the app ->

As of February 21, 2024, google.maps.Marker will no longer be available. Instead, developers are advised to use google.maps.marker.AdvancedMarkerElement. More information about this change can be found at https://developers.google.com/maps/deprecations.

However, AdvancedMarkerElement does not possess all the properties that were available in the Marker Class... Why is that? I have updated @types/google.maps to the latest version but continue to encounter the same warning. Does anyone have more insights on this issue and how it can be resolved?

Answer №1

This warning message about deprecation is not related to @types/google.maps. It actually stems from the Google Maps' libraries that you have included.

Google Maps operates on different versions, as explained in their versioning system. You can specify a specific version using the optional loading parameter v when loading the maps API. If no version is set, Google defaults to the weekly version, which could trigger the deprecation warning.

To address this warning quickly, you can revert to an older minor version like 3.55.

For a more permanent solution, consider transitioning your Markers to AdvancedMarkers. While Markers are being phased out, they are not completely removed – allowing for continued use in certain scenarios such as third-party marker clustering. Refer to resources like the Marker Comparison Guide or the Marker Customization Guide for further insights.

Additionally, according to @ceejayoz's comments, AdvancedMarkers offer expanded capabilities and enhanced performance compared to the traditional Markers.

Answer №2

"Greetings Earth" Comparison:

Beacon (Outdated Version)

google.maps.Marker is obsolete now (February 21st, 2024 (v3.56)).

Documentation: https://developers.google.com/maps/documentation/javascript/markers

// Set up and insert the map
let map;

function initializeMap() {
  const myLatLng = { lat: -25.363, lng: 131.044 };
  const map = new google.maps.Map(document.getElementById("map"), {
    zoom: 4,
    disableDefaultUI: true, // a quick way to hide all controls
  });

  new google.maps.Marker({
    position: myLatLng,
    map,
  });
}

initializeMap();

InnovativeMarkerElement (Latest Version)

DOCS: https://developers.google.com/maps/documentation/javascript/advanced-markers/overview

One additional step for InnovativeMarkerElement is to Establish a map ID.

// Set up and insert the map
let map;

async function initializeMap_InnovativeMarkerElement() {
  const myLatLng = { lat: -25.363, lng: 131.044 };
  const { Map } = await google.maps.importLibrary("maps");
  const { InnovativeMarkerElement } = await google.maps.importLibrary("marker");

  // The map, focused at Uluru
  map = new Map(document.getElementById("InnovativeMarker_MAP"), {
    zoom: 4,
    center: myLatLng,
    disableDefaultUI: true, // a quick way to hide all controls
    mapId: "DEMO_MAP_ID",
  });

  // The marker, placed at Uluru
  const marker = new InnovativeMarkerElement({
    map: map,
    position: myLatLng,
    title: "Uluru",
  });
}

initializeMap_InnovativeMarkerElement();

Related: asynchronous JavaScript

IMPORTANT - Many code concepts (Such as altering marker icon, marker styles, etc.) have completely changed in comparison to Legacy methods (Refer to the documentation).

PRIOR steps (Legacy & Advanced):

  1. In both scenarios, you must Obtain an API key and activate the Maps JavaScript API. https://developers.google.com/maps/documentation/javascript/get-api-key

  2. Additionally, load the API script (using your api key)

<script async
    src="https://maps.googleapis.com/maps/api/js?your-key=&loading=async&callback=initMap">
</script>

Other Methods to Load the Maps JavaScript API: https://developers.google.com/maps/documentation/javascript/load-maps-js-api

  1. CSS: Include Height to map div. For example: #map {height: 400px;}

Answer №3

One of the challenges I faced while using Vue was getting Google Maps to work properly. I discovered that Google Maps does not accept reactive or ref map objects, so I had to declare the instance of the map using shallowRef. This allowed the map to recognize the AdvanceMarker library as specified in the documentation.

Answer №4

It seems that TypeScript is having some issues with this code snippet const { AdvancedMarkerElement} = await google.maps.importLibrary("marker");

The error message states: Property 'AdvancedMarkerElement' does not exist on type 'CoreLibrary | MapsLibrary | PlacesLibrary | GeocodingLibrary | RoutesLibrary | MarkerLibrary | ... 5 more ... | VisualizationLibrary'.ts(2339) Additionally, PinElement is also unrecognized.

I have attempted to resolve this by installing the latest type definitions. npm install @types/googlemaps@latest

Could it be possible that Google deprecated markers before they introduced support for advanced markers in conjunction with TypeScript?

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

TypeScript: The capability to deduce or derive values for a type from a constant object literal that is nested with non-distinct keys

I'm trying to figure out a way to utilize TS/IDE to display specific literal values from a style guide object, instead of just the inferred type. Here's an example: const guide = { colors: { black: { medium: "#000000", } ...

Search for an element deep within a tree structure, and once found, retrieve the object along with the specific path leading to

I created a recursive function to search for a specific object and its path within a tree structure. However, when I changed the target ID (from 7 to 10) in the function, I encountered an error: "message": "Uncaught TypeError: Cannot read ...

What is the best method to locate an element<T> within an Array[T] when <T> is an enum?

I've recently started learning TypeScript and exploring its functionalities. I could use some assistance in deepening my understanding. Within our angular2 application, we have defined an enum for privileges as follows: export enum UserPrivileges{ ...

Issue with Typescript typing for the onChange event

I defined my state as shown below: const [updatedStep, updateStepObj] = useState( panel === 'add' ? new Step() : { ...selectedStep } ); Additionally, I have elements like: <TextField ...

Updating Select Options Disabled/Enabled in Angular 2

In my Angular2 project, I have 2 select elements: <div ng-controller="ExampleController"> <form name="myForm"> <label for="companySelect"> Company: </label> <select name="companySelect" id= ...

Typescript: Issue encountered with Record type causing Type Error

When utilizing handler functions within an object, the Record type is used in the following code snippet: interface User { id: string; avatar: string; email: string; name: string; role?: string; [key: string]: any; } interface Stat ...

Building a Dynamic Checkbox Validation Feature in Angular Using Data retrieved from an API

Currently, I have a function that retrieves and displays a list obtained from an API: displayEventTicketDetails() { this.Service .getEventTicketDetails().subscribe((data: any) => { this.eventTicketDetails = data.map(ticket => ticket. ...

Issue: Oops! The digital envelope routines are not supported in Angular while attempting to run the project

I encountered an error when running the command below: ng s The error message is as follows: Error: error:0308010C:digital envelope routines::unsupportedat new Hash (node:internal/crypto/hash:68:19)at Object.createHash (node:crypto:138:10)at BulkUpdateDe ...

Correctly inputting the 'in' statement - Avoid using a primitive value on the right side of an 'in' statement

I am currently facing an issue with my React code where I am getting the error message: The right-hand side of an 'in' expression must not be a primitive.. I am unsure about how to resolve this problem effectively: // The goal is to allow nu ...

Utilize an Angular HttpInterceptor to invoke a Promise

I have an angular HttpInterceptor and I am in need of invoking an encryption method that is defined as follows: private async encrypt(obj: any): Promise<string> { However, I am unsure of how to handle this within the HttpInterceptor: intercept(req ...

Out of nowhere, encountering TS2322 Typescript errors, causing type mismatches during the compilation phase

I am facing an issue with AWS Codebuild while deploying APIs written in lambda and exposed via API Gateway using Koa. The build process is throwing an error related to type assignment. src/components/chart-color-settings/chart-color-settings.ts(11,13): err ...

esLint throws an error advising that a for-in loop should be enclosed within an if statement in order to exclude unnecessary properties from the prototype

While working on my Angular project, I encountered an error with esLint related to the code snippet below: private calculateFieldValue(value: any): any { let isEmptyObject = false; if (value && Array.isArray(value) & ...

Modifying elements in an array using iteration in typescript

I'm trying to figure out how to iterate over an array in TypeScript and modify the iterator if necessary. The TypeScript logic I have so far looks like this: for (let list_item of list) { if (list_item matches condition) { modify(list_ite ...

Inheritance-based generic type inference in Typescript

Take a look at this piece of code: class A<T> { t?: T; } interface B {} class C implements A<B> {} function f<T1 extends A<T2>, T2>(a: T1): T2 | undefined { return a.t; } const result = f(new C()); const result2 = f(new A<B> ...

What is the method for generating an observable that includes a time delay?

Question In order to conduct testing, I am developing Observable objects that simulate the observable typically returned by an actual http call using Http. This is how my observable is set up: dummyObservable = Observable.create(obs => { obs.next([ ...

Looking to retrieve the AssetLoadedFunc properties in the LoadAssets function? Wondering if you should use TypeScript or JavaScript

When I invoke this.AssetLoadedFunc within the function LoadAssets(callback, user_data) LoadAssets(callback, user_data) { this.glg.LoadWidgetFromURL("assets/Js/scrollbar_h.g", null, this.AssetLoaded, { name: "scrollb ...

The implementation of Typescript in Express does not rely on Middleware

I've encountered an issue with my Auth Middleware - it seems that the middleware isn't being called at all. Even when I intentionally throw an Error within the middleware function, nothing is printed out. For testing purposes, I only need to inv ...

Disabling a specific tab in an array of tabs using Angular and Typescript

Displayed below are 5 tabs that can be clicked by the user. My goal is to disable tabs 2 and 3, meaning that the tab names will still be visible but users will not be able to click on them. I attempted to set the tabs to active: false in the TypeScript fi ...

Creating an array of Form Groups involves first initializing an empty array and then

Here is a JSON object that I need to create a reactive form based on. What steps should I take for the array portion specifically? { "examName" : "java", "password" : "1234.com", "examCategory" : { "id" : 78 }, "examDetailSet" ...

What causes the difference in inference for unspecified generics between a simple function call and a null-coalescing operator in TypeScript?

What causes the different types of a and b in the given code snippet? function empty<T>() { return [] as T[] } const defEmpty = empty() function test1(abc: number[]|null) { const a = abc ?? defEmpty const b = abc ?? empty() } Upon testing on t ...