google-map-js
Advanced tools
Comparing version 1.0.1 to 1.0.3
{ | ||
"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" | ||
} | ||
} |
#!/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 }; |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
No README
QualityPackage does not have a README. This may indicate a failed publish or a low quality package.
Found 1 instance in 1 package
7941
1
4
151
1
46
- Removedgoogle-map-js@^1.0.0