Markup Google Map: Add Custom Markers and Data Layers
In this article
Markup Google Maps by adding custom markers and layers through Google My Maps for simple use or the Maps API for developers.
A real estate agent in Gurugram marks 20 available plots in a specific sector using different colored pins to represent price brackets. They draw a blue polygon around the residential zone and a red line to show the proposed metro route.
Select the Tool for Your Map Markup
Decide between Google My Maps and the Google Maps Platform API based on your technical skill and the intended use of the map.
Google My Maps is a free, browser-based tool for creating personal maps. It allows you to drop pins, draw shapes, and import data without writing code. This tool is suitable for planning a trip, mapping a small number of business locations, or creating a visual guide for a small team.
The Google Maps Platform API is for developers who need to embed a map into a website or application. It allows for dynamic updates, such as markers that change based on a user's search query or real-time data feeds. This method requires an API key from the Google Cloud Console and basic knowledge of JavaScript.
One common misconception is that you can edit the public Google Map directly to add permanent markers for others to see. You cannot change the base map; you instead create a separate layer of data that sits on top of the map, which you then share or embed.
Create Custom Layers with Google My Maps
Start by visiting the My Maps section of your Google account. Click Create a New Map to open the editor.
Use the search bar to find a specific address or coordinate. When the pin appears, click Add to Map to save it as a permanent marker. You can then click the paint bucket icon to change the marker color or select a different icon from the library to represent specific categories, such as a house icon for residential properties.
Organize your data using layers. A layer is a group of markers or shapes that can be toggled on or off. For example, one layer can contain all "Available Plots" and another can contain "Sold Plots". Each map allows for up to 10 layers.
Draw shapes to define areas. Select the Draw a line tool to trace a route or create a polygon. A polygon is a closed shape that can be filled with color, which is useful for marking delivery zones or neighborhood boundaries. Once a shape is closed, you can name it and add a description that appears when a user clicks the area.
Code Dynamic Markers Using the Maps API
To markup a map programmatically, you must first set up a project in the Google Cloud Console and enable the Maps JavaScript API.
Generate an API key and restrict it to your website domain to prevent unauthorized use. In your HTML file, load the API script using your key. You then initialize the map by specifying a center point using latitude and longitude coordinates and a zoom level, typically between 1 and 20.
Create a marker by defining a new google.maps.Marker object. You must provide the map instance and the position coordinates. To change the look of the marker, use the icon property to link to a custom PNG or SVG image.
Add an InfoWindow to provide more detail. This is a small popup that appears when a user clicks a marker. You can populate this window with HTML, such as the name of a business or a link to a product page. For a logistics company mapping 100 warehouses, this allows them to show the warehouse manager's name and contact details on click.
Labels can differ by version of the API, so check the official documentation for the most recent property names when customizing marker labels.
Structure Your CSV for Bulk Location Imports
Manually adding 100 pins is inefficient. Use a CSV or KML file to import large datasets into My Maps.
Create a spreadsheet with clear column headers. The most critical columns are Name, Latitude, and Longitude. If you do not have coordinates, you can use a full Address column, though coordinates are more accurate. Additional columns like Description, Category, or Price will be imported as data associated with each pin.
Ensure there are no empty rows or merged cells in your spreadsheet. A single formatting error, such as a comma inside a data cell without quotes, can cause the import to fail or shift data into the wrong columns.
Consider a worked example for a delivery network in Bengaluru. A manager creates a CSV with 50 rows. Column A is the Hub Name, Column B is the Latitude (e.g., 12.9716), Column C is the Longitude (e.g., 77.5946), and Column D is the Hub Capacity. Upon importing, My Maps asks which column to use for the marker position (Latitude/Longitude) and which to use for the marker title (Hub Name).
Fix Marker Clustering and Overlap Problems
When you markup a map with hundreds of points in a small area, markers will overlap, making the map unreadable.
Use marker clustering for API-based maps. Clustering groups nearby markers into a single circle with a number indicating how many pins are inside. As the user zooms in, the cluster breaks apart into individual markers. This prevents the browser from slowing down and keeps the visual interface clean.
Adjust the z-index for overlapping shapes. If you have a large area polygon and several small markers inside it, ensure the markers have a higher z-index than the polygon. This ensures the pins stay on top and remain clickable.
Control visibility through zoom levels. You can write a script that only displays certain markers when the user zooms in past level 12. This prevents a city-wide map from looking cluttered with every single street-level detail visible at once.
Set Access Permissions for Shared Maps
Once your markup is complete, you must decide who can see or edit the data.
In My Maps, click the Share button. You can keep the map private, share it with specific email addresses, or set it to Public. If you set it to Public, anyone with the link can view the markers and shapes you created.
To put the map on a website, use the Embed on my site option. This generates an iframe HTML code. Note that the map must be set to Public for the embed to work for all visitors.
For API-based maps, manage costs by monitoring your usage in the Cloud Console. While Google provides a recurring monthly credit, high-traffic sites may exceed this. For a business with a budget of Rs 5,000 per month for map services, setting a billing alert at Rs 3,000 helps prevent unexpected charges. Check the Google Cloud Console for current billing rates and credit amounts.
If you encounter a 403 error on an embedded map, check your API key restrictions. Ensure the domain listed in the restrictions exactly matches the URL where the map is hosted.