How can I get city name from a latitude and longitude point?

后端 未结 11 1223
感情败类
感情败类 2020-11-28 03:07

Is there a way to get a city name from a latitude and longitude point using the google maps api for javascript?

If so could I please see an example?

11条回答
  •  星月不相逢
    2020-11-28 03:16

    In case if you don't want to use google geocoding API than you can refer to few other Free APIs for the development purpose. for example i used [mapquest] API in order to get the location name.

    you can fetch location name easily by implementing this following function

     const fetchLocationName = async (lat,lng) => {
        await fetch(
          'https://www.mapquestapi.com/geocoding/v1/reverse?key=API-Key&location='+lat+'%2C'+lng+'&outFormat=json&thumbMaps=false',
        )
          .then((response) => response.json())
          .then((responseJson) => {
            console.log(
              'ADDRESS GEOCODE is BACK!! => ' + JSON.stringify(responseJson),
            );
          });
      };

提交回复
热议问题