Skip to content

Commit

Permalink
Routing Directions API (#2)
Browse files Browse the repository at this point in the history
* Routing directions API

* fixing lint errors

* adding badge

* Update README.md

* updating readme file

* adding badges to readme
  • Loading branch information
iSanjayAchar authored Jul 19, 2024
1 parent 7f7395b commit 8dd2b9f
Show file tree
Hide file tree
Showing 12 changed files with 408 additions and 55 deletions.
114 changes: 66 additions & 48 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,65 +1,83 @@
# OLA Maps SDK (WIP)
A Node.js Library for Easy Integration with OLA Maps API
# OLA Maps SDK
This JavaScript SDK provides a seamless interface to interact with the OLA Maps API, simplifying geocoding, reverse geocoding, and routing operations.
<br />
<br />
[![Codacy Badge](https://app.codacy.com/project/badge/Grade/cebb7bf6c07048ccbd6fdf756d56b0bf)](https://app.codacy.com/gh/iSanjayAchar/ola-maps-node-sdk/dashboard?utm_source=gh&utm_medium=referral&utm_content=&utm_campaign=Badge_grade)
[![Codacy Badge](https://app.codacy.com/project/badge/Coverage/cebb7bf6c07048ccbd6fdf756d56b0bf)](https://app.codacy.com/gh/iSanjayAchar/ola-maps-node-sdk/dashboard?utm_source=gh&utm_medium=referral&utm_content=&utm_campaign=Badge_coverage)
[![TypeScript](https://img.shields.io/badge/%3C%2F%3E-TypeScript-%230074c1.svg)](http://www.typescriptlang.org/)
![NPM Version](https://img.shields.io/npm/v/ola-maps)
![Licence](https://img.shields.io/badge/license-MIT-blue)

### Installation
Install the SDK using npm:
```bash
npm i --save ola-maps
```
npm i -S ola-maps
# OR
Or using yarn:
```bash
yarn add ola-maps
```

### Modules
The SDK consists of two main modules:
1. **Places**: Provides functionality for autocomplete, geocoding, and reverse geocoding. For more details, check the [Places documentation](/documentation/places.md).
2. **Routing**: Enables the calculation of directions between locations. For more details, check the [Routing documentation](/documentation/routing.md)

### Authentication
While OLA Map APIs support two type of authentication, this SDK only supports only authentication using `API_KEY`. To generate `API_KEY`, check the documentation - https://maps.olakrutrim.com/docs/auth
This SDK supports authentication using `API_KEY`. Generate your API key by following the instructions in the OLA Maps documentation: https://maps.olakrutrim.com/docs/auth

### Support
1. Places
- [x] Autocomplete
- [x] Geocode
- [x] Reverse Geocode
2. Routing
- [ ] Direction
### Basic Example
```javascript
import { Places, Routing } from "ola-maps";

### Places
Comprehensive set of APIs to access OLA Maps API with ease
const placesClient = new Places("YOUR_API_KEY");
const routingClient = new Routing("YOUR_API_KEY");

#### Auto Complete
Autocomplete provides intuitive suggestions of places to be looked up. This helps accurate lookup of places based on the text provided. This solves a lot of use cases like lookup of popular places like restaurants, malls, etc.
async function main() {
const autocompleteResult = await placesClient.autocomplete("Koramangala");
console.log(autocompleteResult);

```
import { Places } from "ola-maps";
const geocodeResult = await placesClient.geocode("Regent Insignia, 4th Block, 17th Main, Koramangala");
console.log(geocodeResult);

const places = new Places("API_KEY", "VERSION"); // Version is optional
const reverseGeocodeResult = await placesClient.reverse_geocode(12.9716, 77.5946);
console.log(reverseGeocodeResult);

async function query(input) {
const result = places.autocomplete(input);
console.log(result);
const origin = { lat: 12.9716, lng: 77.5946 }; // Bengaluru
const destination = { lat: 19.0760, lng: 72.8777 }; // Mumbai
const directionResult = await routingClient.direction(origin, destination);
console.log(directionResult);
}
```

#### Geocode
Forward Geocoding API helps translate real-world text-based addresses into geographic coordinates. This is useful in mapping services, route planning, location-based searches, and delivery logistics.

main();
```
import { Places } from "ola-maps";

const places = new Places("API_KEY", "VERSION"); // Version is optional
async function query(input) {
const result = places.geocode(input);
console.log(result);
}
```

#### Reverse Geocode
Reverse Geocoding API helps in translating coordinates to real world text based addressing. This is helpful in scenarios like taxi pickup, taxi drop, delivery/courier, etc.

```
import { Places } from "ola-maps";
const places = new Places("API_KEY", "VERSION"); // Version is optional
async function query(input) {
const result = places.reverse_geocode(input);
console.log(result);
}
```
### Issues
If you encounter any problems or have feature requests, please file an issue on our GitHub repository - https://github.com/iSanjayAchar/ola-maps-node-sdk/issues/new

### Contributors ✨
<table>
<tbody>
<td align="center" valign="top" width="14.28%">
<a href="https://github.com/iSanjayAchar">
<img src="https://avatars.githubusercontent.com/u/11937721?v=3?s=100" width="100px;" alt="Kent C. Dodds" />
<br />
<sub>
<b>Sanjay Achar</b>
</sub>
</a>
</td>
<td align="center" valign="top" width="14.28%">
<a href="https://github.com/JeevanAchar">
<img src="https://avatars.githubusercontent.com/u/114219448?v=3?s=100" width="100px;" alt="Kent C. Dodds" />
<br />
<sub>
<b>Jeevan V</b>
</sub>
</a>
</td>
</tbody>
</table>

### Licence
This SDK is released under the MIT License.
3 changes: 2 additions & 1 deletion dev_test/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import * as dotenv from "dotenv";
dotenv.config();

import "./places";
// import "./places";
import "./routing";
2 changes: 1 addition & 1 deletion dev_test/places.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@ const places = new Places(apiKey);

// places.autocomplete("sadsadsadsadsadsdsads").then(console.log).catch(console.error)
// places.geocoding("271").then(console.log).catch(console.error);
places.reverse_geocoding("12.931316595874005", "77.61649243443775").then(console.log).catch(console.error);
places.reverse_geocode("12.931316595874005", "77.61649243443775").then(console.log).catch(console.error);
13 changes: 13 additions & 0 deletions dev_test/routing.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import {Routing} from "../src";

const apiKey = process.env.OLA_MAPS_API_KEY as string;

const routing = new Routing(apiKey);

routing.direction({
lat: "18.76029027465273",
lng: "73.3814242364375"
}, {
lat: "18.73354223011708",
lng: "73.44587966939002"
}).then(console.log).catch(console.error);
82 changes: 82 additions & 0 deletions documentation/places.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
# Places API
This JavaScript library provides a client to interact with the Places API. It simplifies the process of making autocomplete, geocoding, and reverse geocoding requests. It uses Axios under the hood for making HTTP requests.

### Usage
To use the client, you'll need an API key. Create a new instance of the Places class and pass your API key and optional version (defaulting to `v1`)

**Note:** An API key from the Places service is required for authentication. More details regarding the authentication can be found here.

### Methods
The `Places` class provides the following methods:
1. `autocomplete(input, options?)`
- Performs autocomplete based on the provided input.
- `input` - The user's search input.
- `options` - (Optional) Additional options like language, location, radius, etc... <br />
```typescript
type PlacesOption = {
"X-Request-Id"?: string;
"X-Correlation-Id"?: string;
language?: ILanguage;
location?: {
latitude: string | number;
longitude: string | number;
};
radius?: number;
strictbounds?: boolean;
}
```
2. `geocode(address, options?)`
- Converts an address into geographic coordinates (latitude and longitude).
- `address` - The address to geocode.
- `options` - (Optional) Additional options like language, bounding box, etc... <br />
```typescript
type GeocodingOption = {
"X-Request-Id"?: string;
"X-Correlation-Id"?: string;
language?: ILanguage;
bounding?: {
x: {
latitude: string | number;
longitude: string | number;
},
y: {
latitude: string | number;
longitude: string | number;
}
}
}
```
3. `reverse_geocode(lat, lng, options?)`
- Converts latitude and longitude into an address.
- `lat` - The latitude coordinate.
- `lng` - The longitude coordinate.
- `options` - (Optional) Additional options like correlation ID and request ID.
```typescript
type ReverseGeocodingOption = {
"X-Request-Id"?: string;
"X-Correlation-Id"?: string;
}
```
### Example
```javascript
async function main() {
import { Places } from "ola-maps";

const placesClient = new Places("YOUR_API_KEY");

// Autocomplete
const autocompleteResult = await placesClient.autocomplete("Koramangala");
console.log(autocompleteResult);

// Geocoding
const geocodeResult = await placesClient.geocode("Regent Insignia, 4thBlock, 17th Main, Koramangala");
console.log(geocodeResult);

// Reverse Geocoding
const reverseGeocodeResult = await placesClient.reverse_geocode(37.4221, -122.0841);
console.log(reverseGeocodeResult);
}

main();
```
43 changes: 43 additions & 0 deletions documentation/routing.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
# Places API
This JavaScript library provides a client to interact with the OLA Maps Routing API. It simplifies the process of calculating directions between locations using Axios for HTTP requests

### Usage
To use the client, you'll need an API key. Create a new instance of the Routing class and pass your API key and optional version (defaulting to `v1`)

**Note:** An API key from the Places service is required for authentication. More details regarding the authentication can be found here.

### Methods
The `Routing` class provides the following methods:
1. `direction(origin, destination, options?)`
- `origin` (Coordinates) - Object with lat (latitude) and lng (longitude) of the starting point.
- `destination` (Coordinates) - Object with lat (latitude) and lng (longitude) of the ending point.
- `options` - (Optional) Additional options like language, location, radius, etc... <br />
```typescript
type DirectionOptions = {
"X-Request-Id"?: string;
"X-Correlation-Id"?: string;
waypoints?: Array<[string | number, string | number]>;
alternatives?: boolean;
steps?: boolean;
overview?: "full" | "simplied" | false;
language?: ILanguage;
traffic_metadata?: boolean;
}
```
### Example
```javascript
import { Routing } from "ola-maps";

async function main() {
const routing = new Routing("YOUR_API_KEY");

const origin = { lat: 12.9716, lng: 77.5946 }; // Bengaluru
const destination = { lat: 19.0760, lng: 72.8777 }; // Mumbai

const directionResult = await routing.direction(origin, destination);
console.log(directionResult);
}

main();
```
8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "ola-maps",
"version": "0.0.4",
"description": "A Node.js Library for Easy Integration with OLA Maps API",
"version": "0.0.5",
"description": "JavaScript SDK for a seamless interface to interact with the OLA Maps API, simplifying geocoding, reverse geocoding, and routing operations.",
"keywords": [
"ola",
"ola maps",
Expand All @@ -20,10 +20,10 @@
],
"license": "MIT",
"author": "isanjayachar <[email protected]",
"homepage": "https://github.com/isanjayachar/ola-maps-sdk",
"homepage": "https://github.com/isanjayachar/ola-maps-node-sdk",
"repository": {
"type": "git",
"url": "git+https://github.com/isanjayachar/ola-maps-sdk.git"
"url": "git+https://github.com/isanjayachar/ola-maps-node-sdk.git"
},
"main": "dist/index.js",
"scripts": {
Expand Down
1 change: 1 addition & 0 deletions src/const.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ const ENV: {
autoCompletePath: "/places/{version}/autocomplete",
geoCodingPath: "/places/{version}/geocode",
reverseGeoCodingPath: "/places/{version}/reverse-geocode",
directionPath: "/routing/{version}/directions",
},
};

Expand Down
1 change: 1 addition & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
export * from "./places";
export * from "./routing";
Loading

0 comments on commit 8dd2b9f

Please sign in to comment.