How to Use OpenStreetMap as a Free Alternative to Google Maps
Google Maps has been the default choice for developers building location-based applications for years. But for many teams, especially those operating at scale, pricing has become a real concern.
Google Maps provides a $200 monthly credit, but beyond that, usage is billed per request. For applications like logistics, ride-hailing, or fleet tracking – where thousands of requests are made daily – costs can grow quickly depending on which APIs you use.
OpenStreetMap (OSM) offers a different approach. Instead of charging for access to map APIs, it provides free, open geographic data that you can build on.
What is OpenStreetMap?
OpenStreetMap is a free, open, and community-driven map of the world. Anyone can contribute to it, and anyone can use it.
Unlike Google Maps, which gives access through controlled APIs, OpenStreetMap gives you access to the underlying geographic data itself.
This data is structured in three main ways:
- Nodes: single points (for example, a bus stop or a tree)
- Ways: lines or shapes made up of nodes (like roads or buildings)
- Relations: groups of nodes and ways that define more complex things (like routes or boundaries)
Each of these elements includes tags (key-value pairs), such as:
- highway=residential
- name=Allen Avenue
So instead of just displaying a map, OpenStreetMap lets you work with structured geographic data.
The Open Database License (ODbL)
OpenStreetMap data is licensed under the ODbL. This means:
- You can use it for commercial or personal projects
- You must give proper attribution
This makes it especially useful for developers who want clarity around data ownership.
Why Choose OpenStreetMap Over Google Maps?
Cost
OpenStreetMap data is free to use. But it’s important to be precise here: OpenStreetMap removes licensing costs, but not infrastructure costs.
You may still need to pay for:
- Tile hosting
- Geocoding services
- Routing engines
Control
With Google Maps, you can’t modify the data, and you rely entirely on Google’s APIs
But with OpenStreetMap, you can download and store the data, modify it, and build custom solutions on top of it.
Customization
OpenStreetMap gives you more flexibility:
- You control how maps are rendered
- You can choose or build your own map styles
- You can create domain-specific maps
Adoption
OpenStreetMap is widely used. Companies like Meta and Microsoft contribute to it, and many platforms rely on it directly or indirectly.
This shows that the ecosystem is mature and reliable.
Understanding the OpenStreetMap Ecosystem
A common mistake is to think that OpenStreetMap works like a single API. It doesn’t.
Instead, it works as a set of layers, where each layer handles a different responsibility.
Data Layer (OpenStreetMap)
This is the foundation. It contains all the raw geographic data:
- Roads
- Buildings
- Landmarks
- Boundaries
This is what you are ultimately working with.
Rendering Layer (Leaflet, MapLibre)
Raw data isn’t visual. It needs to be turned into something users can see.
There are two main approaches:
- Raster tiles (used by Leaflet): pre-rendered images
- Vector tiles (used by MapLibre): raw geometry styled in the browser
Leaflet uses raster tiles by default, which makes it simple and fast to start with.
Services Layer
This is what makes your map interactive.
Geocoding converts addresses into coordinates, while reverse geocoding converts coordinates into addresses.
Routing calculates directions between points, and tile servers provide the actual map visuals.
How Everything Works Together
When a user searches for a place:
- The user enters a location
- A geocoding service converts it into coordinates
- The map updates its position
- A tile server provides the visual map
Each part is separate, but they work together to create the full experience.
How to Integrate OpenStreetMap in React with Leaflet
Let’s build a simple map.
Step 1: Create a React App
npm create vite@latest osm-app — –template react
cd osm-app
npm install
Step 2: Install Dependencies
npm install leaflet react-leaflet
npm install –save-dev @types/leaflet
Step 3: Import Leaflet CSS
import ‘leaflet/dist/leaflet.css’;
This is required for the map to display correctly.
Step 4: Create a Map Component
import { MapContainer, TileLayer, Marker, Popup } from ‘react-leaflet’;
function Map() {
const position = [51.505, -0.09]; // latitude, longitude
return (
<MapContainer
center={position}
zoom={13}
style={{ height: ‘100vh’ }}
>
<TileLayer
attribution=’© <a href=”https://www.openstreetmap.org/copyright”>OpenStreetMap</a> contributors’
url=”https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png”
/>
<Marker position={position}>
<Popup>Hello from OpenStreetMap</Popup>
</Marker>
</MapContainer>
);
}
export default Map;
Let’s break down the important parts here:
- MapContainer initializes the map.
- center is where the map starts
- zoom is how close the view is
- style must include height, or the map won’t show
TileLayer defines where the map visuals come from.
{z} is the zoom level
{x}, {y} are the tile coordinates
{s} is the subdomain
Each tile is a small image (usually 256×256 pixels), and Leaflet combines them to form the full map.
Marker adds a point on the map at a specific coordinate.
Popup displays information when the marker is clicked.
Important note:
The default OpenStreetMap tile server:
https://{s}.tile.openstreetmap.org/{z}/{x}/{y








