AndyVROMO

Google Maps Geocode API JavaScript Call

Feb 19th, 2020
727
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. const googleMapsLookup = (address, apiKey) =>
  2.   fetch(`https://maps.googleapis.com/maps/api/geocode/json?address=${encodeURI(address)}&key=${apiKey}`)
  3.   .then(res => res.json())
  4.   .then(data => {
  5.     const { lat, lng } = data.results[0].geometry.location
  6.     return { lat, lon: lng }
  7.   })
  8.   .catch(() => ({ lat: 0, lon: 0 }))
Add Comment
Please, Sign In to add comment