Created
September 26, 2017 11:41
-
-
Save hanipcode/2ed074aa978b28e212ef4d02df81fc96 to your computer and use it in GitHub Desktop.
fungsi getPredictionWithDetail
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
| 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