Skip to content

Instantly share code, notes, and snippets.

@hanipcode
Created September 26, 2017 11:41
Show Gist options
  • Select an option

  • Save hanipcode/2ed074aa978b28e212ef4d02df81fc96 to your computer and use it in GitHub Desktop.

Select an option

Save hanipcode/2ed074aa978b28e212ef4d02df81fc96 to your computer and use it in GitHub Desktop.
fungsi getPredictionWithDetail
function getPredictionWithDetail(searchQuery, key) {
return getPredictionList(searchQuery, key)
.then(result => {
const predictions = result.predictions;
const predictionsPromise = predictions.map(prediction =>
getPlaceDetails(prediction.place_id, key)
);
return Promise.all(predictionsPromise);
})
.then(data => {
const predictionDetails = data.map(predictionItem => ({
name: predictionItem.result.name,
formatted_address: predictionItem.result.formatted_address,
geometry: predictionItem.result.geometry,
placeId: predictionItem.result.place_id
}));
return predictionDetails;
})
.catch(err => {
console.log(err);
return err;
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment