location-picker icon indicating copy to clipboard operation
location-picker copied to clipboard

Cannot find namespace 'google' (Angular 7.2)

Open DoubyCz opened this issue 7 years ago • 3 comments

I've just followed instructions in readme.md "Angular Example" and this error occured:

ERROR in node_modules/location-picker/dist/types/location-picker.d.ts(1,23): error TS2688: Cannot find type definition file for 'googlemaps'.
node_modules/location-picker/dist/types/location-picker.d.ts(2,21): error TS2503: Cannot find namespace 'google'.
node_modules/location-picker/dist/types/location-picker.d.ts(3,14): error TS2503: Cannot find namespace 'google'.

Angular CLI: 7.2.3 Node: 8.15.0 OS: linux x64 Angular: 7.2.2

DoubyCz avatar Mar 01 '19 08:03 DoubyCz

I found a solution:

npm install --save @types/google-maps

maybe this should be mentioned in readme.md 'Angular example'.

DoubyCz avatar Mar 01 '19 08:03 DoubyCz

I found a solution:

npm install --save @types/google-maps

maybe this should be mentioned in readme.md 'Angular example'.

Thanks.. Faced the same issue.

karthi-the-programmer avatar Sep 17 '19 05:09 karthi-the-programmer

Fixed in 3.0. The default map is OpenStreetMap, and the type declarations no longer reference the global google namespace: only the optional location-picker/google entry uses @types/google.maps (an optional peer dependency). An Angular app needs no extra type packages:

import { Component, CUSTOM_ELEMENTS_SCHEMA } from '@angular/core';
import { FormControl, ReactiveFormsModule } from '@angular/forms';
import 'location-picker';

@Component({
  selector: 'app-store-form',
  standalone: true,
  imports: [ReactiveFormsModule],
  schemas: [CUSTOM_ELEMENTS_SCHEMA],
  template: `<location-picker [formControl]="location" ngDefaultControl search style="height:360px"></location-picker>`,
})
export class StoreFormComponent {
  location = new FormControl('', { nonNullable: true }); // "lat,lng"
}

ngDefaultControl is all Angular needs; there is no custom ControlValueAccessor. If you use Google Maps, npm i -D @types/google.maps (the old @types/googlemaps package is deprecated). Full Angular example: https://github.com/cyphercodes/location-picker/blob/master/docs/frameworks.md#angular-17. Closing as fixed in 3.0.0.

cyphercodes avatar Oct 30 '26 15:10 cyphercodes