xxxxxxxxxx
Simply pass latitude, longitude and your Google API Key to the following query string, you will get a json array, fetch your city from there.
https://maps.googleapis.com/maps/api/geocode/json?latlng=44.4647452,7.3553838&key=YOUR_API_KEY
Note: Ensure that no space exists between the latitude and longitude values when passed in the latlng parameter.
Click here to get an API key
xxxxxxxxxx
function getCoordinates(address){
fetch("https://maps.googleapis.com/maps/api/geocode/json?address="+address+'&key='+API_KEY)
.then(response => response.json())
.then(data => {
const latitude = data.results[0].geometry.location.lat;
const longitude = data.results[0].geometry.location.lng;
console.log({latitude, longitude})
})
}