@satyajeetsahoo/maps
v2.1.3
Published
Small Google Maps and Ola Maps client using native fetch
Maintainers
Readme
@satyajeetsahoo/maps
A unified Maps service supporting Google Maps and Ola Maps.
Why use this package?
Vendor lock-in with Maps providers (like Google Maps) can become extremely expensive as your app scales. This package provides a standardized interface for Geocoding, Reverse Geocoding, and Distance Calculations. If you decide to switch from Google Maps to Ola Maps for cost savings, you simply change one line of configuration—your application logic remains completely untouched.
Features
- Provider Agnostic: Switch between Google and Ola instantly.
- Normalized Responses: You always get the exact same JSON structure back, regardless of which provider is fulfilling the request.
Installation
npm install @satyajeetsahoo/mapsConfiguration & Strategies
Google Maps Strategy
import { MapsFactory } from '@satyajeetsahoo/maps';
export const maps = MapsFactory.createMapsStrategy('google', {
apiKey: process.env.GOOGLE_MAPS_API_KEY
});Ola Maps Strategy
import { MapsFactory } from '@satyajeetsahoo/maps';
export const maps = MapsFactory.createMapsStrategy('ola', {
clientId: process.env.OLA_CLIENT_ID,
clientSecret: process.env.OLA_CLIENT_SECRET
});Detailed Examples & JSON Responses
1. Geocoding (Address to Coordinates)
const location = await maps.geocode('Bhubaneswar, Odisha');Response Output:
{
"lat": 20.2960587,
"lng": 85.8245398,
"formattedAddress": "Bhubaneswar, Odisha, India",
"raw": { /* original provider payload */ }
}2. Reverse Geocoding (Coordinates to Address)
const address = await maps.reverseGeocode(20.2961, 85.8245);
// => "Bhubaneswar, Odisha, India"3. Distance Matrix
const distance = await maps.getDistance('Bhubaneswar', 'Cuttack', 'driving');Response Output:
{
"distanceMeters": 26000,
"durationSeconds": 1800,
"distanceText": "26.0 km",
"durationText": "30 mins"
}