1.0.6 • Published 6 years ago

getcoords v1.0.6

Weekly downloads
3
License
MIT
Repository
github
Last release
6 years ago

🌐 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

1.0.6

6 years ago

1.0.5

6 years ago

1.0.4

6 years ago

1.0.3

6 years ago

1.0.2

6 years ago

1.0.0

6 years ago

0.0.2

6 years ago