DEV Community

TutsCoder
TutsCoder

Posted on • Originally published at tutscoder.com

How to get address location from latitude and longitude in Angular15+

In this article, we will see how we can get address location from latitude and longitude in Angular15+ by using the Reverse Geocoding technique.

What is Reverse Geocoding?

Reverse geocoding is the process to convert the latitude and longitude coordinates to a readable address.

How to Get address location from latitude and longitude in Angular15+

Generate map componenent 

ng g c map
 getAddress(lat: number, lng: number): Promise<any> {

return new Promise((resolve, reject) => {

this.http

.get<any>(

https://maps.googleapis.com/maps/api/geocode/json?latlng=${lat},${lng}&amp;amp;key=${environment.googleMapsApiKey}

)

.pipe(

map((geoData) => {

if (!geoData || !geoData.results || geoData.results.length === 0)

throw null;

return geoData.results[0];

})

)

.subscribe(

(data) => {

resolve(data);

},

(e) => {

reject(e);

}

);

});

}

and now use this function as below:

this.getAddress(23.01997577399075, 73.07245691797758);

AWS GenAI LIVE image

How is generative AI increasing efficiency?

Join AWS GenAI LIVE! to find out how gen AI is reshaping productivity, streamlining processes, and driving innovation.

Learn more

Top comments (0)

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more