Skip to content

Instantly share code, notes, and snippets.

@badnorseman
Created January 26, 2017 22:15
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Embed
What would you like to do?
GoogleMaps
const googleMapsClient = require('@google/maps').createClient({
key: process.env.GOOGLE_SERVER_KEY,
});
module.exports.placesAutoComplete = (input, type) =>
new Promise((resolve, reject) =>
googleMapsClient.placesAutoComplete({
input,
type,
}, (error, res) => {
if (error) {
reject(error);
} else {
const data = res.json.predictions;
resolve(data);
}
})
);
const filter = require('lodash/fp/filter');
const includes = require('lodash/fp/includes');
const googleMaps = require('../../js/apis/googleMaps');
/**
* Step 1: Search all types.
* Step 2: Filter non-geocodes types.
*/
const searchPlace = query =>
googleMaps.placesAutoComplete(query, '')
.then(locations =>
filter(location =>
includes('establishment', location.types),
locations))
.catch((error) => {
throw new Error(error);
});
module.exports = searchPlace;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment