React
Interactive Maps
Web Development
JavaScript
Mapping Libraries
User Experience
Frontend Development

How to Create Interactive Maps in React

Deepak Tewatia
August 28, 2025
3 min read

Introduction

Want to make your app stand out? Learn how to create fun and interactive maps using React. This guide will show you simple steps to add maps, markers, and cool features. With clear examples, you’ll see how easy it is to engage users and bring a new level to your projects. Let’s get started!

Why Use Maps in Your Apps?

Maps help users understand locations better. They can visualize data in a way that is easy to grasp. By using interactive maps, you give users more control. They can zoom in, pan around, and click on things to get more information. This can make their experience much more enjoyable.

Choosing a Mapping Library

To add maps to your React app, you’ll need a mapping library. Here are a couple of popular choices:

Both libraries have their pros and cons. Leaflet is lighter and more straightforward, while Google Maps has more data and features. Choose what fits your project best.

Setting Up Your Project

Let’s get your React project ready. First, make sure you have Node.js installed. If you don’t, you can download it from the Node.js website.

Now, create a new React app. Open your terminal and run:

npx create-react-app my-map-app

After that, navigate into your project folder:

cd my-map-app

Next, you need to install the mapping library you chose. For example, if you go with React Leaflet, run:

npm install react-leaflet leaflet

Adding Your First Map

Now it’s time to add a map. Open the src/App.js file. First, import the needed components from the library:

import { MapContainer, TileLayer } from 'react-leaflet';

Then, replace the default content in the App component with the following code:

function App() {
    return (
        <MapContainer center={[51.505, -0.09]} zoom={13} style={{ height: "100vh", width: "100%" }}>
            <TileLayer
                url="https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png"
                attribution='© <a href="http://osm.org/copyright">OpenStreetMap</a> contributors'
            />
        </MapContainer>
    );
}

This code sets up a simple map centered on London. You can change the coordinates in the center prop to focus on a different area.

Adding Markers

Markers are cool because they highlight specific locations. You can easily add markers using React Leaflet. First, import the Marker and Popup components:

import { Marker, Popup } from 'react-leaflet';

Now, add a marker inside the MapContainer:

<Marker position={[51.505, -0.09]}>
    <Popup>
        A pretty CSS3 popup. <br /> Easily customizable.
    </Popup>
</Marker>

This code places a marker at the same location as our map and adds a popup with some text. You can add multiple markers by repeating this code with different coordinates.

Customizing Your Map

Here’s the thing: you can customize your map to fit your app’s style. You can change the map's style, marker icons, and popups. For example, you can use custom icons for your markers by importing an image:

import myIcon from './my-icon.png';

You can then create a custom marker like this:

const customIcon = new L.Icon({
    iconUrl: myIcon,
    iconSize: [25, 41],
    iconAnchor: [12, 41],
    popupAnchor: [1, -34],
    shadowUrl: '/path/to/marker-shadow.png',
    shadowSize: [41, 41],
});

Replace the default marker with the custom one:

<Marker position={[51.505, -0.09]} icon={customIcon}>
    <Popup>
        Custom marker with an image.
    </Popup>
</Marker>

Conclusion

Now you know the basics of creating interactive maps with React. You can add maps, markers, and customize them to make your app unique. As you get more comfortable, explore more advanced features like layers, shapes, and event handling. The possibilities are endless!

With this knowledge, you can boost user engagement and bring your projects to life. Happy coding!