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

Top comments (0)