Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

google-map-js

Package Overview
Dependencies
Maintainers
1
Versions
10
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

google-map-js - npm Package Compare versions

Comparing version 1.0.1 to 1.0.3

.prettierrc

5

package.json
{
"name": "google-map-js",
"version": "1.0.1",
"version": "1.0.3",
"description": "Pass form latitude longititude and to latitude longitude to get the route for the two points with google api.",

@@ -12,5 +12,4 @@ "main": "server.js",

"dependencies": {
"@googlemaps/google-maps-services-js": "^3.3.31",
"google-map-js": "^1.0.0"
"@googlemaps/google-maps-services-js": "^3.3.31"
}
}

70

server.js
#!/usr/bin/env node
const { Client } = require('@googlemaps/google-maps-services-js');
const client = new Client({});

@@ -24,5 +25,5 @@ /**

if(!googleMapApiKey){
return resolve('Map key not found');
}
if (!googleMapApiKey) {
return resolve('Map key not found');
}

@@ -33,4 +34,2 @@ if (latitudeA && longitudeA && latitudeB && longitudeB) {

const client = new Client({});
client

@@ -85,3 +84,3 @@ .directions({

const mapUrl = `https://maps.googleapis.com/maps/api/staticmap?size=600x400&&format=png&maptype=roadmap&markers=size:mid%7Ccolor:red%7Clabel:Loss%Adress%7C${latitudeA},${longitudeA}&markers=size:mid%7Ccolor:red%7Clabel:Adjuster%Adddress%7C${latitudeB},${longitudeB}&path=color:0x039BE5FF%7Cweight:5%7Cgeodesic:true%7C${path}&key=${googleMapApiKey}`;
/**

@@ -114,2 +113,59 @@ * response?.json.routes?.[0]?.legs?.[0]?.distance?.value -> it is used to total miles in meters ( Number ) format

module.exports = { DirectionsService };
/**
* Google map using get address location latitude and longitude
*
* @param {string} Address From latitude - Default not Null
* @param {string} googleMapApiKey Google map API key - Default not Null
* @returns {Promise<{ mapDistanceUrl: string, distance: Number }>} Promise that resolves to { routeDetails: Returns full details of distance route details, mapDistanceUrl: Distance map URL, distance: Distance with miles in 2 digits }
*/
const GetAddressToLatitudeLongitude = (address, googleMapApiKey) => {
return new Promise((resolve, reject) => {
try {
// Create a new client instance
const client = new Client({});
// Define the address you want to geocode
// const address = 'Your Address';
if (!googleMapApiKey) {
return resolve('Map key not found');
}
if (address) {
// Use the geocode method to get latitude and longitude
client
.geocode({
params: {
address: address,
key: googleMapApiKey
}
})
.then(response => {
const results = response.data.results;
if (results.length > 0) {
const location = results[0].geometry.location;
const latitude = location.lat;
const longitude = location.lng;
return resolve({
latitude: latitude,
longitude: longitude
});
} else {
return resolve('No results found for the address.');
}
})
.catch(error => {
return reject('Error:', error.message);
});
} else {
return resolve('Required address parameter.');
}
} catch (error) {
return reject(error);
}
});
};
module.exports = { DirectionsService, GetAddressToLatitudeLongitude };
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc