Created
January 26, 2017 22:15
-
-
Save badnorseman/cab326ff9a28f47463fc98210dd50f0d to your computer and use it in GitHub Desktop.
GoogleMaps
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | |
} | |
}) | |
); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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