Ola Map SDK

API Reference

Complete API reference for Ola Map SDK classes and methods

API Reference

Complete reference documentation for the Ola Map SDK.

Table of Contents

OlaMapsClient

The main client class that provides access to all Ola Maps API endpoints.

Constructor

new OlaMapsClient(apiKey)

Parameters:

  • apiKey (string) - Your Ola Maps API key

Example:

const OlaMapsClient = require('ola-map-sdk');
const client = new OlaMapsClient('YOUR_API_KEY');

Properties

After initialization, the client provides access to these endpoint objects:

  • client.places - Places API methods
  • client.routing - Routing API methods
  • client.roads - Roads API methods
  • client.geofencing - Geofencing API methods
  • client.elevation - Elevation API methods
  • client.tiles - Tiles API methods

Map Helper Methods

getStyleURL(styleName)

Get the full style URL for MapLibre GL.

Parameters:

  • styleName (string) - Style name (default: 'default-light-standard')

Returns: string - Full style URL

Example:

const url = client.getStyleURL('default-dark-standard');
// "https://api.olamaps.io/tiles/vector/v1/styles/default-dark-standard/style.json"

getTransformRequest()

Get a transform request function for MapLibre authentication.

Returns: Function - Transform request callback

Example:

const transformRequest = client.getTransformRequest();
// Use with MapLibre GL
const map = new maplibregl.Map({
    container: 'map',
    style: client.getStyleURL(),
    transformRequest: transformRequest
});

getMapOptions(options)

Get complete MapLibre GL map options.

Parameters:

  • options (object) - Map configuration
    • container (string|HTMLElement) - Map container
    • style (string) - Style name
    • center (array) - Center coordinates [lng, lat]
    • zoom (number) - Zoom level

Returns: object - Complete MapLibre GL options

Example:

const map = new maplibregl.Map(client.getMapOptions({
    container: 'map',
    center: [77.61, 12.93],
    zoom: 14
}));

Places API

autocomplete(input, options)

Get place suggestions as users type.

Parameters:

  • input (string) - Search text
  • options (object, optional)
    • location (string) - Bias location (lat,lng)
    • radius (number) - Search radius in meters
    • language (string) - Language code
    • types (string) - Filter by type
    • strictbounds (boolean) - Strict boundaries

Returns: Promise<object> - Autocomplete results

Example:

const results = await client.places.autocomplete('Bangalore', {
    location: '12.93,77.61',
    radius: 5000
});

geocode(address, language)

Convert address to coordinates.

Parameters:

  • address (string) - Address to geocode
  • language (string, optional) - Language code

Returns: Promise<object> - Geocoding results

Example:

const result = await client.places.geocode('Taj Mahal, Agra');

reverseGeocode(lat, lng, language)

Convert coordinates to address.

Parameters:

  • lat (number) - Latitude
  • lng (number) - Longitude
  • language (string, optional) - Language code

Returns: Promise<object> - Reverse geocoding results

Example:

const result = await client.places.reverseGeocode(28.6139, 77.2090);

placeDetails(placeId, language)

Get detailed information about a place.

Parameters:

  • placeId (string) - Place ID
  • language (string, optional) - Language code

Returns: Promise<object> - Place details

Example:

const details = await client.places.placeDetails('ola-platform:5000039498427');

placeDetailsAdvanced(placeId, language)

Get advanced place details with more information.

Parameters:

  • placeId (string) - Place ID
  • language (string, optional) - Language code

Returns: Promise<object> - Advanced place details

Example:

const details = await client.places.placeDetailsAdvanced('ola-platform:5000039498427');

nearbySearch(location, options)

Search for places near a location.

Parameters:

  • location (string) - Center point (lat,lng)
  • options (object, optional)
    • types (string) - Place type
    • radius (number) - Search radius
    • language (string) - Language
    • rankBy (string) - Ranking method
    • limit (number) - Max results

Returns: Promise<object> - Search results

Example:

const results = await client.places.nearbySearch('12.93,77.61', {
    types: 'restaurant',
    radius: 1000
});

nearbySearchAdvanced(location, options)

Advanced nearby search with additional options.

Parameters: Same as nearbySearch

Returns: Promise<object> - Search results

textSearch(input, options)

Search for places using text query.

Parameters:

  • input (string) - Search query
  • options (object, optional)
    • location (string) - Bias location
    • radius (number) - Search radius
    • types (string) - Place type
    • size (number) - Max results

Returns: Promise<object> - Search results

Example:

const results = await client.places.textSearch('Cafes in Koramangala');

addressValidation(address)

Validate and standardize an address.

Parameters:

  • address (string) - Address to validate

Returns: Promise<object> - Validation result

Example:

const validation = await client.places.addressValidation('7, Lok Kalyan Marg, New Delhi');

photo(photoReference)

Get place photo by reference.

Parameters:

  • photoReference (string) - Photo reference ID

Returns: Promise<ArrayBuffer> - Photo data

Example:

const photo = await client.places.photo('photo_reference_id');

Routing API

getDirections(origin, destination, options)

Get turn-by-turn directions between locations.

Parameters:

  • origin (object) - Origin { lat, lon }
  • destination (object) - Destination { lat, lon }
  • options (object, optional)
    • mode (string) - Travel mode
    • steps (boolean) - Include steps
    • overview (string) - Geometry detail
    • traffic_metadata (boolean) - Traffic info
    • language (string) - Language
    • alternatives (boolean) - Alternative routes
    • waypoints (array) - Intermediate points

Returns: Promise<object> - Route directions

Example:

const route = await client.routing.getDirections(
    { lat: 12.99, lon: 77.54 },
    { lat: 12.97, lon: 77.58 },
    { traffic_metadata: true }
);

getDirectionsBasic(origin, destination, options)

Get basic directions without traffic.

Parameters: Similar to getDirections (without traffic options)

Returns: Promise<object> - Route directions

getDistanceMatrix(origins, destinations, options)

Calculate distances between multiple points.

Parameters:

  • origins (string) - Pipe-separated origins
  • destinations (string) - Pipe-separated destinations
  • options (object, optional)
    • mode (string) - Travel mode
    • route_preference (string) - Route preference

Returns: Promise<object> - Distance matrix

Example:

const matrix = await client.routing.getDistanceMatrix(
    '12.99,77.54|12.97,77.58',
    '12.93,77.61',
    { mode: 'driving' }
);

getDistanceMatrixBasic(origins, destinations, options)

Basic distance matrix calculation.

Parameters: Similar to getDistanceMatrix

Returns: Promise<object> - Distance matrix

routeOptimizer(locations, options)

Optimize waypoint order.

Parameters:

  • locations (string) - Pipe-separated coordinates
  • options (object, optional)
    • source (string) - Start point
    • destination (string) - End point
    • round_trip (boolean) - Return to start
    • mode (string) - Travel mode

Returns: Promise<object> - Optimized route

Example:

const optimized = await client.routing.routeOptimizer(
    '12.99,77.54|12.97,77.58|12.93,77.61',
    { round_trip: true }
);

fleetPlanner(inputData, strategy, options)

Multi-vehicle route planning.

Parameters:

  • inputData (object|string) - Package and vehicle data or file path
  • strategy (string) - Optimization strategy
  • options (object, optional)
    • route_preference (string) - Route preference

Returns: Promise<object> - Fleet routes

Example:

const result = await client.routing.fleetPlanner(
    { packages: [...], vehicles: [...] },
    'optimal'
);

Roads API

snapToRoad(points, enhancePath)

Snap GPS coordinates to roads.

Parameters:

  • points (string) - Pipe-separated coordinates (max 50)
  • enhancePath (boolean) - Add intermediate points

Returns: Promise<object> - Snapped points

Example:

const snapped = await client.roads.snapToRoad(
    '12.99,77.67|12.99,77.65',
    true
);

nearestRoads(points, mode, radius)

Find nearest roads to coordinates.

Parameters:

  • points (string) - Pipe-separated coordinates (max 100)
  • mode (string) - Travel mode: DRIVING, WALKING, etc.
  • radius (number) - Search radius in meters

Returns: Promise<object> - Nearest roads

Example:

const roads = await client.roads.nearestRoads(
    '12.99,77.67',
    'DRIVING',
    500
);

speedLimits(points, snapStrategy)

Get speed limits for road segments.

Parameters:

  • points (string) - Pipe-separated coordinates (max 50)
  • snapStrategy (string) - snaptoroad or nearestroad

Returns: Promise<object> - Speed limit data

Example:

const speeds = await client.roads.speedLimits(
    '13.06,77.59|13.06,77.59'
);

Geofencing API

create(geofenceData)

Create a new geofence.

Parameters:

  • geofenceData (object)
    • name (string) - Geofence name
    • type (string) - circle or polygon
    • coordinates (array) - Coordinates
    • radius (number) - Radius (for circles)
    • status (string) - active or inactive
    • projectId (string) - Project ID
    • metadata (object) - Custom metadata

Returns: Promise<object> - Created geofence

Example:

const fence = await client.geofencing.create({
    name: 'Warehouse',
    type: 'circle',
    coordinates: [[28.7041, 77.1025]],
    radius: 100,
    projectId: 'my-project'
});

getById(id)

Get geofence by ID.

Parameters:

  • id (string) - Geofence ID

Returns: Promise<object> - Geofence details

update(id, geofenceData)

Update existing geofence.

Parameters:

  • id (string) - Geofence ID
  • geofenceData (object) - Updated data

Returns: Promise<object> - Updated geofence

deleteById(id)

Delete geofence by ID.

Parameters:

  • id (string) - Geofence ID

Returns: Promise<object> - Deletion result

list(projectId, page, size)

List geofences in a project.

Parameters:

  • projectId (string) - Project ID
  • page (number) - Page number
  • size (number) - Items per page

Returns: Promise<object> - List of geofences

checkStatus(geofenceId, coordinates)

Check if coordinates are inside geofence.

Parameters:

  • geofenceId (string) - Geofence ID
  • coordinates (string) - Coordinates (lat,lng)

Returns: Promise<object> - Status result

Elevation API

getElevation(lat, lng)

Get elevation for single location.

Parameters:

  • lat (number) - Latitude
  • lng (number) - Longitude

Returns: Promise<object> - Elevation data

Example:

const elev = await client.elevation.getElevation(12.93, 77.61);

getMultiElevation(locations)

Get elevations for multiple locations.

Parameters:

  • locations (array) - Array of "lat,lng" strings (max 25)

Returns: Promise<object> - Elevation data

Example:

const elevations = await client.elevation.getMultiElevation([
    '12.93,77.61',
    '12.94,77.62'
]);

Tiles API

getStyles()

Get all available map styles.

Returns: Promise<object> - List of styles

getStyleDetail(styleName)

Get detailed style JSON.

Parameters:

  • styleName (string) - Style name

Returns: Promise<object> - Style specification

getDataTileJSON(datasetName)

Get TileJSON for vector dataset.

Parameters:

  • datasetName (string) - Dataset name

Returns: Promise<object> - TileJSON metadata

getPBFFile(datasetName, z, x, y)

Download vector tile PBF.

Parameters:

  • datasetName (string) - Dataset name
  • z (number) - Zoom level
  • x (number) - Tile X
  • y (number) - Tile Y

Returns: Promise<ArrayBuffer> - PBF data

getFontGlyphs(fontstack, start, end)

Get font glyph data.

Parameters:

  • fontstack (string) - Font name
  • start (number) - Start Unicode
  • end (number) - End Unicode

Returns: Promise<ArrayBuffer> - Glyph data

getStaticMapByCenter(styleName, lon, lat, zoom, width, height, format, options)

Generate static map by center point.

Parameters:

  • styleName (string) - Style name
  • lon (number) - Longitude
  • lat (number) - Latitude
  • zoom (number) - Zoom level
  • width (number) - Image width
  • height (number) - Image height
  • format (string) - png or jpg
  • options (object, optional)
    • marker (string) - Marker specification
    • path (string) - Path specification

Returns: Promise<ArrayBuffer> - Image data

getStaticMapByBBox(styleName, bbox, width, height, format, options)

Generate static map by bounding box.

Parameters:

  • styleName (string) - Style name
  • bbox (object) - Bounding box { minx, miny, maxx, maxy }
  • width (number) - Image width
  • height (number) - Image height
  • format (string) - png or jpg
  • options (object, optional) - Marker and path

Returns: Promise<ArrayBuffer> - Image data

getStaticMapAuto(styleName, width, height, format, options)

Generate static map with auto bounds.

Parameters:

  • styleName (string) - Style name
  • width (number) - Image width
  • height (number) - Image height
  • format (string) - png or jpg
  • options (object, optional) - Marker and path

Returns: Promise<ArrayBuffer> - Image data

get3DTileset()

Get 3D tileset data.

Returns: Promise<object> - 3D tileset JSON

Error Handling

All API methods throw errors on failure. Common error types:

try {
    const result = await client.places.autocomplete('Test');
} catch (error) {
    // Authentication errors
    if (error.message.includes('API key')) {
        console.error('Invalid or missing API key');
    }
    
    // Rate limiting
    else if (error.message.includes('429')) {
        console.error('Rate limit exceeded');
    }
    
    // Not found
    else if (error.message.includes('404')) {
        console.error('Resource not found');
    }
    
    // Bad request
    else if (error.message.includes('400')) {
        console.error('Invalid parameters');
    }
    
    // Server error
    else {
        console.error('API error:', error.message);
    }
}

Type Definitions

Coordinate Object

{
    lat: number,    // Latitude (-90 to 90)
    lng: number     // Longitude (-180 to 180)
}

Location String

Coordinates in "lat,lng" format:

"12.93126,77.61638"

Pipe-Separated Locations

Multiple coordinates separated by pipes:

"12.93,77.61|12.94,77.62|12.95,77.63"

Response Structure

Most responses follow this pattern:

{
    status: "OK" | "ERROR",
    results: [...],  // or data: {...}
    message: "..."   // On errors
}

On this page

API ReferenceTable of ContentsOlaMapsClientConstructorPropertiesMap Helper MethodsgetStyleURL(styleName)getTransformRequest()getMapOptions(options)Places APIautocomplete(input, options)geocode(address, language)reverseGeocode(lat, lng, language)placeDetails(placeId, language)placeDetailsAdvanced(placeId, language)nearbySearch(location, options)nearbySearchAdvanced(location, options)textSearch(input, options)addressValidation(address)photo(photoReference)Routing APIgetDirections(origin, destination, options)getDirectionsBasic(origin, destination, options)getDistanceMatrix(origins, destinations, options)getDistanceMatrixBasic(origins, destinations, options)routeOptimizer(locations, options)fleetPlanner(inputData, strategy, options)Roads APIsnapToRoad(points, enhancePath)nearestRoads(points, mode, radius)speedLimits(points, snapStrategy)Geofencing APIcreate(geofenceData)getById(id)update(id, geofenceData)deleteById(id)list(projectId, page, size)checkStatus(geofenceId, coordinates)Elevation APIgetElevation(lat, lng)getMultiElevation(locations)Tiles APIgetStyles()getStyleDetail(styleName)getDataTileJSON(datasetName)getPBFFile(datasetName, z, x, y)getFontGlyphs(fontstack, start, end)getStaticMapByCenter(styleName, lon, lat, zoom, width, height, format, options)getStaticMapByBBox(styleName, bbox, width, height, format, options)getStaticMapAuto(styleName, width, height, format, options)get3DTileset()Error HandlingType DefinitionsCoordinate ObjectLocation StringPipe-Separated LocationsResponse Structure