https://github.com/melanieseltzer/getcoords
🌐 Get lat and long coordinates from any street address
https://github.com/melanieseltzer/getcoords
coordinates geocoding googlemaps-api latlng
Last synced: about 1 year ago
JSON representation
🌐 Get lat and long coordinates from any street address
- Host: GitHub
- URL: https://github.com/melanieseltzer/getcoords
- Owner: melanieseltzer
- License: mit
- Created: 2018-08-15T06:56:34.000Z (almost 8 years ago)
- Default Branch: master
- Last Pushed: 2018-08-18T15:41:26.000Z (almost 8 years ago)
- Last Synced: 2025-03-06T22:33:52.208Z (over 1 year ago)
- Topics: coordinates, geocoding, googlemaps-api, latlng
- Language: JavaScript
- Homepage:
- Size: 567 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: license
Awesome Lists containing this project
README
# 🌐 getcoords [](https://www.npmjs.com/package/getcoords) [](https://travis-ci.org/melanieseltzer/getcoords) [](https://snyk.io/test/github/melanieseltzer/getcoords)
> 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](https://developers.google.com/maps/documentation/geocoding/start#get-a-key) for instruction on how to obtain the key.
Then, you must set `process.env.GOOGLE_GEOCOORDS_API_KEY` in your project using [dotenv](https://www.npmjs.com/package/dotenv) or similar. You could also set it globally in your shell ([more info](https://unix.stackexchange.com/a/21600)).
If you want to use it on client builds (such as in a React app) you will need to use [dotenv-webpack](https://github.com/mrsteele/dotenv-webpack).
## Usage
```js
// .env
GOOGLE_GEOCOORDS_API_KEY=YOURKEYHERE
```
```js
// 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
- [getcoords-cli](https://github.com/melanieseltzer/getcoords-cli)
## License
MIT © [Melanie Seltzer](https://github.com/melanieseltzer)