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);

Do your career a big favor. Join DEV. (The website you're on right now)

It takes one minute, it's free, and is worth it for your career.

Get started

Community matters

Top comments (0)

AWS Security LIVE!

Tune in for AWS Security LIVE!

Join AWS Security LIVE! for expert insights and actionable tips to protect your organization and keep security teams prepared.

Learn More