wl-google-maps
v1.0.9
Published
Using package find travel distance and time between source and destination and other features.
Downloads
5
Readme
Node.js wrapper for Google Features
Using package find travel distance and time between source and destination and other features.
Installation
npm install wl-google-maps
Initialize
import WLGoogleMaps from 'wl-google-maps';
let wlobj = new WLGoogleMaps('GOOGLE_API_KEY');
To create your google application's API key:
1. Go to the API Console. https://console.developers.google.com/
2. From the projects list, select a project or create a new one.
3. Open the left side menu and select APIs & services.
4. Enable "Geocoding API" & "Diatance Matrix API"
4. On the left, choose Credentials.
5. Click Create credentials and then select API key to get key.
6. Use this while initializing.
Usage
Get Travel time and distance between two locations (Coordinates)
let source_latitude = 16.989065
let source_longitude = 82.247467
let destination_latitude = 17.385044
let destination_longitude = 78.486671
wlobj.calculateDistance(source_latitude,source_longitude,destination_latitude,destination_longitude)
.then((res) => {
console.log(res);
})
.catch((err) => {
console.log(err);
});
Get Travel time and distance between two locations (addresses)
let source_address = 'Kakinada';
let destination_address = 'Hyderabad, India';
wlobj.calculateDistance(source_address,destination_address)
.then((res) => {
console.log(res);
})
.catch((err) => {
console.log(err);
});
Find latitude and longitude from address
let address = 'Kakinada, 533006';
wlobj.getCoordinatesByAddress(address)
.then((res) => {
console.log(JSON.stringify(res));
})
.catch((err) => {
console.log(err);
});
Find address from latitude and longitude
let latitude = 16.989065
let longitude = 82.247467
wlobj.getAddressFromCoordinates(latitude, longitude)
.then((res) => {
console.log(JSON.stringify(res));
})
.catch((err) => {
console.log(err);
});