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

Using NPM in combination with React and TypeScript to incorporate AMD modules

I am currently in the process of setting up a development environment for an application that is written in TypeScript using React. I already have existing TypeScript code that compiles to ES5 and AMD modules. My goal is to avoid any JavaScript transpilat ...

Preventing nested prototype methods from being transferred between objects in a WebWorker

My challenge is to reserialize an object from a WebWorker while maintaining the same definitions. However, upon receiving the message, all of the prototype functions are lost. The current solution I have only works for first level prototype functions, bu ...

Tips for customizing the legend color in Angular-chart.js

In the angular-chart.js documentation, there is a pie/polar chart example with a colored legend in the very last section. While this seems like the solution I need, I encountered an issue: My frontend code mirrors the code from the documentation: <can ...

Is it feasible to securely remove an item from an array within an object without the need for any assertions in a single function?

My interest in this matter stems from curiosity. The title may be a bit complex, so let's simplify it with an example: type ObjType = { items: Array<{ id: number }>; sth: number }; const obj: ObjType = { sth: 3, items: [{ id: 1 }, { id: 2 } ...

Spartacus has the capability to extend or override the PageType enum within the cms.model framework

I am facing a dilemma similar to the Spartacus situation. In brief, I am required to modify the PageType enum in cms.model by either overriding or extending it. The current enum consists of four values (content, product, category, catalog) and I must incl ...

In React, the edit mode fails to display class attributes

When I attempted to combine both the creation and editing functionalities in one form, I encountered a problem. Specifically, I was able to retrieve the correct ID value when editing an element, but I struggled to access the attribute values. import { yup ...

TypeScript Error: The Object prototype must be an Object or null, it cannot be undefined

Just recently, I delved into TypeScript and attempted to convert a JavaScript code to TypeScript while incorporating more object-oriented features. However, I encountered an issue when trying to execute it with cmd using the ns-node command. private usern ...

Button with circular icon in Ionic 4 placed outside of the toolbar or ion-buttons

Is it possible to create a circular, clear icon-only button without using ion-buttons? I am trying to achieve the same style as an icon-only button within ion-buttons (clear and circular). Here is my current code: <ion-button icon-only shape="round" co ...

How can I ensure a function only runs after all imports have been successfully loaded in Vue 3?

Encountering an issue with importing a large quantitative variable in Vue 3. Upon running onMounted, it seems that the import process is not yet complete, resulting in an error indicating that the variable tesvar is "uninitialized". The code snippet prov ...

Experimenting with error boundaries by utilizing the React Testing Library and Jest:

I am facing an issue while writing a test for my error boundary higher-order component (HOC). The problem arises when I mock throwing an error in my wrapped component, causing the test to fail because it recognizes the error as a genuine one instead of und ...

Why is it that I am not receiving JSON data in my Angular application?

I am currently working on a class within a webapi public class ResponseObject { public int Success { get; set; } public string Message { get; set; } public object Data { get; set; } } Within my ASP.NetCore, I have the following method: publi ...

Issue: The UserComponent is attempting to set the property 'id' of an undefined object, resulting in an error

An error has occurred indicating that the property 'id' cannot be set as it is undefined in the UserComponent file of user.component.ts. Here is the TypeScript code: import { Component, OnInit } from "@angular/core"; import { ActivatedRoute, Rou ...

What could be the reason for the tsc command not displaying compilation errors when compiling a particular file?

My file, titled app.ts, contains the following code snippet: interface Foo { bar:String; } const fn = (foo? :Foo) => foo.bar; When I run tsc from the root folder with strict:true in my tsconfig.json file, I receive an error message like this ...

Is the neglected property being discarded?

First things first, let's talk about my class: class FavoriteFooBar { ... isPreferred: boolean = false; constructor() { this.isPreferred = false; } } Using a utility library called Uniquer, I arrange a list of FavoriteFooBar instances to pr ...

Reactive forms in Angular now support changing focus when the Enter key is pressed

I have successfully created a table and a button that generates dynamic rows with inputs inside the table. One issue I'm facing is that when I press enter in the first input, a new row is created (which works), but I can't seem to focus on the ne ...

Troubleshooting a custom pipe issue in Ionic v4 with Angular

I attempted to create a pipe in the ionic -v4 beta version to reverse an array, but encountered a parser error in the template. Below is the example of what I tried: ionic g pipe pipe/reverse Here is the pipe definition: import { Pipe, PipeTransform } f ...

Tips for creating an HTTP only cookie in NestJS

Currently, I am in the process of incorporating JWT authorization with both an accessToken and refreshToken. The requirement is to store these tokens in HTTP-only cookies. Despite attempting this code snippet, I have encountered an issue where the cookies ...

Add a feature to a functional component that is enclosed with React.forwardRef

Within my codebase, there exists a component that is wrapped with React.forwardRef and serves as a compound component. One challenge I encountered was how to preserve the functionality of Form.Item = FormItem; while still having the Form component fun ...

Using GraphQL in React to access a specific field

Here is the code snippet I am working with: interface MutationProps { username: string; Mutation: any; } export const UseCustomMutation: React.FC<MutationProps> | any = (username: any, Mutation: DocumentNode ) => { const [functi ...

Tips for avoiding the transmission of className and style attributes to React components

Hey there! I'm working on a custom button component that needs to accept all ButtonHTMLAttributes except for className and style to avoid any conflicts with styling. I'm using TypeScript with React, but I've run into some issues trying to ac ...