2

I'm using angular-googlemaps(agm) and it's working so far..

But I want to search an address by latitude and longitude, so I found part of the solution here... the problem is:

I followed the following steps:

1 - Installed googlemaps: yarn add @types/googlemaps -D

2 - Import googlemaps in my component: import { } from 'googlemaps';

And when I try to do anything with "google" like this, for example:

const geocoder = new google.maps.Geocoder();

I get the following error:

ERROR ReferenceError: google is not defined

1st. attempt: Declare google this way in my component:

declare var google: any;

2nd. attempt: Put googlemaps inside types in tsconfig.app.json (angular-cli):

...
"types": ["googlemaps"]
...

But the error keeps appearing.

Am I missing something? Thanks in advance.

dev_054
  • 3,448
  • 8
  • 29
  • 56

1 Answers1

0

This might not be the answer you want but as a work around you can use their api :

const location = { longitude, latitude, accuracy };
const baseUrl = "https://maps.googleapis.com/maps/api/geocode/json?";

const url = `${this.baseUrl}latlng=${latitude},${longitude}&key=${API_KEY}`
this.http.get(url).subscribe(r => console.log(r));
Ced
  • 15,847
  • 14
  • 87
  • 146