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

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

In this article, we will see how we can get address location from latitude and longitude in Angular14+ 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 Angular14+

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

Subscribe to our Newsletter

Stay up to date! Get all the latest posts delivered straight to your inbox.

If You Appreciate What We Do Here On TutsCoder, You Should Consider:

If you like what you are reading, please consider buying us a coffee ( or 2 ) as a token of appreciation.

Support Us

We are thankful for your never ending support.

Leave a Comment