Google Maps and React With a Custom Marker

Search for a command to run...

No comments yet. Be the first to comment.
Bun, the hyper-fast JavaScript runtime known for its incredible speed and Zig-based architecture, is being completely rewritten in Rust. For a project that has over 22 million monthly downloads and ea

Next.js 16.3 is almost here, and it's packed with a ton of improvements and let's see them in this post 1.Instant Navigation For a while now, there’s been a valid, lingering debateServer Components vs

It’s official. React has merged its long-awaited Rust port of the React Compiler (formerly known as React Forget) into the main repository. What started as an experimental research project by Joseph S

If you follow modern technology trends, you have likely been led to believe that artificial intelligence is entirely built on Python. Every tutorial, machine learning framework documentation, and open

Just when the JavaScript ecosystem was catching its breath after last week’s TanStack Router compromise, the Mini Shai-Hulud supply chain worm has continued its relentless march. Developed by the thre

Photo by Yucel Moran on Unsplash
Google Map React is a component wrapping a set of the Google Maps API functionality. It allows you to render any React component on the Google Map.
Integrate Google Maps with React (Javascript & Typescript)
Obtain the API key
Creating a custom marker on the map
Adding animations for the custom markers
Displaying the Google map options
Let’s begin by creating a React app using the below command
create-react-app map-example cd map-example npm start
If you would like to use TypeScript for your React application, then use the below command
create-react-app map-example --typescript cd map-example npm start
Now we will install the [google-map-react](https://www.npmjs.com/package/google-map-react) library using the below command.
npm i google-map-react
If you are using TypeScript, then install the types for google-map-react using the below command.
npm i @types/google-map-react
Once the types are installed, we need to get the API key.
To show the maps, you will need an API key to properly authenticate calls.
Go visit the maps platform page. Once there click Getting Started and check the box for Maps. Then click Continue

Then from the dropdown select your Project name. Click Next when you’re brought to the page to enable your APIs. You will now be brought to the following page that displays your API key

Copy the API key and add in your code and you can see the map gets displayed once you run the project using the command npm start

Create a new file named simpleMap.tsx (for JS simpleMap.js) and add the below code
Now we will create a custom marker instead of the text.
Create a file named Marker.tsx and add the below code.
Create a CSS file named Marker.css and add the below code.
Replace the AnyReactComponent with the Marker component like below in SimpleMapExample.tsx
Your output will be like below:

You now know how to create a custom marker. Now we will animate the marker.
Add the below code in Marker.css.
Replace the below code in Marker.tsx.
We will have the custom animation for the marker like below

We can show the native Google Map options bar like street view, map view control. You do so by passing an options object to the Google Maps component.
Add the map options in SimpleMap.tsx like below.
Now you could see the following changes in your map.


Congratulations you have created a simple map with a custom marker and animation in React. Explore more with the plugin. Happy coding :)