npm

getcoords

1.0.6 • Public • Published

🌐 getcoords npm Build Status Known Vulnerabilities

Get lat and long coordinates from any address

getcoords uses the Google Geocoding API to convert any address into geographic coordinates.

Install

$ npm install getcoords

API Key

In order to use the package, you must first obtain a Google API key. Please visit the dev docs for instruction on how to obtain the key.

Then, you must set process.env.GOOGLE_GEOCOORDS_API_KEY in your project using dotenv or similar. You could also set it globally in your shell (more info).

If you want to use it on client builds (such as in a React app) you will need to use dotenv-webpack.

Usage

// .env
GOOGLE_GEOCOORDS_API_KEY=YOURKEYHERE
// app.js
 
// Import the package
import getCoords from 'getcoords';
 
// Load your .env file
require('dotenv').config();
 
// Promise syntax
getCoords('Los Angeles, CA 90034')
  .then(res => console.log(res))
  .catch(error => console.log('Something went wrong'));
 
// Or use with Async/await!
(async () => {
  try {
    const latlng = await getCoords('Los Angeles, CA 90034');
    console.log(latlng);
  } catch (error) {
    console.error(error);
  }
})();
 
//=> { lat: 34.1022444, lng: -118.3401679 } 

Related

License

MIT © Melanie Seltzer

Package Sidebar

Install

npm i getcoords

Weekly Downloads

3

Version

1.0.6

License

MIT

Unpacked Size

6.76 kB

Total Files

4

Last publish

Collaborators

  • melanieseltzer