Last active
February 21, 2024 11:53
-
-
Save shawndumas/ca92d167af0532110a5c to your computer and use it in GitHub Desktop.
async await
This file contains 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
async function func () { | |
const url = 'https://maps.googleapis.com/maps/api/geocode/json?address=94043&sensor=false'; | |
const { results: [ result ] } = await fetch(url).then((response) => response.json()); | |
return JSON.stringify(result, null, 2); | |
} | |
func().then(console.log.bind(console)); | |
/* | |
{ | |
"address_components": [ | |
{ | |
"long_name": "94043", | |
"short_name": "94043", | |
"types": [ | |
"postal_code" | |
] | |
}, | |
{ | |
"long_name": "Mountain View", | |
"short_name": "Mountain View", | |
"types": [ | |
"locality", | |
"political" | |
] | |
}, | |
{ | |
"long_name": "California", | |
"short_name": "CA", | |
"types": [ | |
"administrative_area_level_1", | |
"political" | |
] | |
}, | |
{ | |
"long_name": "United States", | |
"short_name": "US", | |
"types": [ | |
"country", | |
"political" | |
] | |
} | |
], | |
"formatted_address": "Mountain View, CA 94043, USA", | |
"geometry": { | |
"bounds": { | |
"northeast": { | |
"lat": 37.4640869, | |
"lng": -122.0359899 | |
}, | |
"southwest": { | |
"lat": 37.3857439, | |
"lng": -122.10842 | |
} | |
}, | |
"location": { | |
"lat": 37.428434, | |
"lng": -122.0723816 | |
}, | |
"location_type": "APPROXIMATE", | |
"viewport": { | |
"northeast": { | |
"lat": 37.4640869, | |
"lng": -122.0359899 | |
}, | |
"southwest": { | |
"lat": 37.3857439, | |
"lng": -122.10842 | |
} | |
} | |
}, | |
"place_id": "ChIJoQmen1G3j4ARbhoe7nVBEoQ", | |
"types": [ | |
"postal_code" | |
] | |
} | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment