I'm creating a Typescript app that takes an address from the user and displays it on a Google map.
I've created a type GoogleGeocodingResponse that accepts the GeoCoding response.data.results as {geometry: {location: {lat: Number; lng: Number}}}
Then I use Axios to:
.get<GoogleGeocodingResponse>(
`https://maps.googleapis.com/maps/api/geocode/json?
address=${encodeURI(enteredAddress)}&key=${GOOGLE_API_KEY}`
)
The part I don't get is, how can I use this data to create a LatLng? I've been using:
const coordinates = new google.maps.LatLng({
lat: Number(response.data.results[0].geometry.location.lat),
lng: Number(response.data.results[0].geometry.location.lng),
})
Casting to type Number works, but it seems I should be able to get the data directly from the GoogleGeocodingResponse without having to cast first. Do I have to specifically define a type? Is there a type in @types/google.maps I can use? Something else?