Skip to content

Convert an array of place names into an array of coordinates.

Notifications You must be signed in to change notification settings

plmrry/places-to-coords

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

13 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Convert place names to coordinates

Setup

Create a .env file and add a GOOGLE_MAPS_API_KEY variable:

GOOGLE_MAPS_API_KEY=AIz...ezI

Install stuff:

npm install

Example

node example.js

Usage

Give places-to-coords an array of strings and a callback.

The callback will be called every time a response is received.

const placesToCoords = require('./places-to-coords');
const placeNames = [ 'Germany', 'Arlington, VA' ];
const callback = (err, data) => console.log('Got one.', data)
placesToCoords(placeNames, callback);

The response data will look like this:

{ 
  address: 'New York, NY',
  location: { 
    lat: 40.7127837, 
    lng: -74.0059413 
  } 
}

A Promise is also returned once all the results are collected:

const placesToCoords = require('./places-to-coords');
const placeNames = [ 'Germany', 'Arlington, VA' ];
placesToCoords(placeNames)
  .then(results => {
    console.log("We're all done here.", results);
  });

Note: The order of responses will not match the order of addresses in the array.

About

Convert an array of place names into an array of coordinates.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published