The fastest way to add multiple pins to a map
The simplest approach is to use Google Maps Embed or Leaflet, a free open-source library. Google Maps Embed lets you drop pins directly in the Google Maps interface, then copy a single line of code into your HTML. Leaflet requires you to write a small JavaScript loop that reads your pin data and places each one on the map — it takes about 20 lines of code and gives you more control over how the map looks and behaves.
If you need something between those two — more customization than Google Maps Embed but less code than Leaflet — Mapbox offers a middle ground with a visual editor and straightforward documentation. All three work in modern browsers without special plugins.
The choice depends on how many pins you need, whether the data changes, and how much the map's appearance matters to your site. A restaurant chain with 50 locations needs a different solution than a real estate site with 200 listings that update weekly.
Key Takeaways
- Google Maps Embed is fastest for a static map with a handful of pins — you mark them in the Google Maps interface and paste one line of code into your page.
- Leaflet is free and open-source, works offline, and lets you style the map however you want, but requires writing JavaScript to loop through your pin data.
- Mapbox sits between the two, offering a visual editor with more customization than Google Maps Embed and less code than Leaflet.
- If your pins come from a database or change regularly, you need a solution that reads data from a file or API — Google Maps Embed alone cannot do this.
- All three solutions work on mobile devices and do not require users to install anything.
Using Google Maps Embed for a quick static map
Open Google Maps in your browser and search for your first location. Click the three-line menu in the top left, then select Share. Click the Embed a map tab. Google generates an iframe code — a single HTML tag that displays the map. Copy that code and paste it into your HTML file between the <body> tags.
To add more pins, go back to Google Maps, search for each location, and click the red pin that appears. Click Save and add it to a new list. Once all pins are in the list, open the list, click the three-dot menu, and select Share. The embed code now includes all the pins you saved. Copy and paste the updated code into your HTML.
This method works well for up to 10 or 15 pins. Beyond that, the map becomes cluttered, and you may want to let users filter by category or search. Google Maps Embed does not support filtering — you would need Leaflet or Mapbox for that.
Building a map with Leaflet and a data file
Leaflet requires three pieces: an HTML file that holds the map container, a CSS file that sizes it, and a JavaScript file that creates the map and adds pins. Start by creating a folder for your project and adding an HTML file called index.html.
In the <head> section, link to Leaflet's CSS and JavaScript files from a content delivery network (CDN). Then add a <div> with an id of map in the <body>. In your CSS file, set the map div to a width and height — for example, width: 100%; height: 500px;.
In your JavaScript file, create a Leaflet map object centered on a latitude and longitude. Then create an array of objects, each containing a location name, latitude, longitude, and description. Loop through the array and call L.marker() for each pin, passing the coordinates. Attach a popup to each marker so users see the description when they click. Save the JavaScript file and link to it at the bottom of your HTML body.
This approach scales to hundreds of pins. If your data lives in a database or updates regularly, you can fetch it from an API instead of hardcoding it into the JavaScript array.
Reading pin data from a JSON file
Instead of writing pin coordinates directly into your JavaScript, you can store them in a separate JSON file — a plain-text format that JavaScript can read. Create a file called pins.json and structure it as an array of objects, each with name, latitude, longitude, and description fields.
In your JavaScript file, use the fetch() function to load the JSON file, then loop through the data and create markers the same way you would with a hardcoded array. This keeps your data separate from your code, making it easier to update locations without touching JavaScript.
If your pins come from a database or a third-party service, you can replace the JSON file with an API endpoint. The fetch() call works the same way — you just point it to the API URL instead of a local file.
Customizing pins and clusters with Leaflet plugins
By default, Leaflet uses the same blue pin for every location. To change pin colors or icons, create a custom icon object using L.icon() and pass it to the marker when you create it. You can use a different color for each category — red for restaurants, blue for hotels, green for parks — by checking the location's category field and assigning the right icon.
If you have hundreds of pins, the map becomes slow and hard to read. Leaflet.markercluster is a free plugin that groups nearby pins into a single cluster circle. When users zoom in, the clusters break apart into individual pins. Add the plugin's CSS and JavaScript files to your HTML, then wrap your marker creation in a L.markerClusterGroup() instead of adding markers directly to the map.
You can also add a search box using Leaflet-search or Leaflet-control-geocoder, letting users find locations by name or address. These plugins integrate with your existing marker data.
Using Mapbox for more control with less code
Mapbox is a mapping platform that sits between Google Maps Embed and Leaflet. It offers a visual editor called Mapbox Studio where you can design your map's colors, fonts, and layers without writing code. You can upload a CSV or GeoJSON file of your pins, and Mapbox places them automatically.
To embed the map on your site, you generate an access token and paste a few lines of JavaScript into your HTML. Mapbox handles the styling and interactivity — no CSS or complex JavaScript loops required. If you need to update pins, you re-upload your data file and Mapbox refreshes the map.
Mapbox has a free tier that covers most small projects. Beyond a certain number of map views per month, you pay based on usage. Leaflet is always free because it is open-source, but Mapbox's visual editor and hosting can save time if you want a polished map without building it from scratch.
Comparing the three approaches
| Method | Setup time | Customization | Best for | Cost |
|---|---|---|---|---|
| Google Maps Embed | 5 minutes | Low — colors and styling are fixed | Static maps with fewer than 15 pins | Free up to 25,000 map loads per month |
| Leaflet | 30 minutes to 1 hour | High — full control over appearance and behavior | Maps with many pins, custom styling, or offline use | Free and open-source |
| Mapbox | 15 minutes | Medium — visual editor plus some code customization | Maps that need custom styling but not full control | Free tier; paid plans start around $5/month |
Frequently Asked Questions
Can I update pins without rebuilding the map?
Yes, if you store pins in a JSON file or API. Change the data, and the map updates the next time the page loads. Google Maps Embed requires you to manually edit the map in Google Maps and re-embed the code. Leaflet and Mapbox both read from external data sources, so updates happen automatically.
What if I have thousands of pins?
Use Leaflet with marker clustering. Clusters group nearby pins into circles that expand when users zoom in. Without clustering, thousands of pins make the map slow and unreadable. Mapbox also supports clustering through its visual editor.
Do I need a server to host a map with multiple pins?
No. Google Maps Embed and Leaflet both work on static HTML pages hosted anywhere. If your pins come from a JSON file, the file must be on the same server as your HTML. If pins come from an API, the API can be on any server — your browser fetches the data when the page loads.
Can I let users search for pins by name or address?
Google Maps Embed does not support search. Leaflet and Mapbox both work with search plugins. Leaflet-search and Leaflet-control-geocoder are free options. Mapbox includes search functionality in its paid plans.
Which option works best on mobile?
All three work on mobile devices. Google Maps Embed and Mapbox are optimized for touch by default. Leaflet works on mobile but requires you to test and adjust touch interactions — for example, making sure pinch-to-zoom works and that popups are easy to close on a small screen.