I have been struggling for a couple of hours trying to make work googlemaps PlaceResult
in my Angular 2 project that uses Angular-cli
.
I had to install googlemaps
using @types and add it under the attribute "types"
of my tsconfig.json
configuration file.
{
...
"types": [
"google-maps"
]
}
}
And I succeed to use google.maps.places.PlaceResult
in my Angular 2 Component by simply importing it !
import { ActivatedRoute, Params } from "@angular/router";
import { MapsAPILoader } from "angular2-google-maps/core";
import PlaceResult = google.maps.places.PlaceResult;
import GeocoderRequest = google.maps.GeocoderRequest;
...
Several hours later, I had to work with google.maps.Marker
, which is in the same definition file as PlaceResult
and GeocoderRequest
. So I simply imported it as below :
[Line 12] import PlaceResult = google.maps.places.PlaceResult;
[Line 13] import GeocoderRequest = google.maps.GeocoderRequest;
[Line 14] import Marker = google.maps.Marker;
[Line 15] import LatLng = google.maps.LatLng;
...
But I had an unexpected error at runtime saying
Uncaught ReferenceError: google is not defined search.component.ts:14
at Object.444 (search.component.ts:14)
at __webpack_require__ (bootstrap 26c2b97…:52)
at Object.727 (app.config.ts:11)
at __webpack_require__ (bootstrap 26c2b97…:52)
at Object.602 (src async:7)
at __webpack_require__ (bootstrap 26c2b97…:52)
at Object.1258 (.*$:7)
at __webpack_require__ (bootstrap 26c2b97…:52)
at webpackJsonpCallback (bootstrap 26c2b97…:23)
at main.bundle.js:1
Please note that webpack throws this error at line 14 of my component. Meaning that (and correct me if I'm wrong) the previous lines (that uses the same "google") worked well.
Am'I missing something ?
I use :
- Angular : 2.4
- Angular-CLI : 1.0.0-beta.24
- typescript : 2.0.10
- angular2-google-maps: 0.17.0