How to Find Location by Latitude and Longitude in JavaScript
Hello artisan,
In this example, I will share with you the source code for finding a location by latitude and longitude google maps javascript. Sometimes we need location from latitude and longitude in javascript if there is no location from the server side.
So I am here to show you get the address from latitude and longitude from google Maps in javascript. The main goal of this lesson is to get addresses from latitude and longitude without a google map API key.
So we will get location from latitude and longitude without a google map API key. Let's see the example:
const fetchLocationName = async (lat,lng) => {
var street;
await fetch('https://www.mapquestapi.com/geocoding/v1/reverse?key=YOUR_KEY_FROM_MAP_QUESTION_API_SITE&location='+lat+'%2C'+lng+'')
.then((response) => response.json())
.then((responseJson) => {
let location = JSON.stringify(responseJson);
let final = JSON.parse(location);
street = final.results[0].locations[0].street;
});
return street;
};
Just pass lat and long while calling this function. I will give you the exact street address.
Read also: Polygonal Google Map in Laravel with Multiple Markers
Hope it can help you.