IONIC 中没有 MapsAPILoader 提供程序

exe*_*elc 5 google-maps typescript ionic-framework angular

目的是用谷歌地图显示搜索。

我在离子/角度项目中遇到此错误

    运行时错误
    没有 MapsAPILoader 的提供者!
    堆
    错误:没有 MapsAPILoader 的提供程序!
        在注入错误(http://localhost:8103/build/main.js:1655:86)
        在 noProviderError (http://localhost:8103/build/main.js:1693:12)
        在 ReflectiveInjector_._throwOrNull (http://localhost:8103/build/main.js:3194:19)
        在 ReflectiveInjector_._getByKeyDefault (http://localhost:8103/build/main.js:3233:25)
        在 ReflectiveInjector_._getByKey (http://localhost:8103/build/main.js:3165:25)
        在 ReflectiveInjector_.get (http://localhost:8103/build/main.js:3034:21)
        在AppModuleInjector.NgModuleInjector.get(http://localhost:8103/build/main.js:3981:52)
        在resolveDep(http://localhost:8103/build/main.js:11441:45)
        在createClass(http://localhost:8103/build/main.js:11305:32)
        在 createDirectiveInstance (http://localhost:8103/build/main.js:11125:37)

在应用程序模块中

    从'@agm/core'导入{AgmCoreModule};
    从“angular2-google-maps/core/services/google-maps-api-wrapper”导入{GoogleMapsAPIWrapper};


     进口:[
            AgmCoreModule.forRoot({
                apiKey:'********',库:[“地点”]
            })
          ]

然后在组件页面

    从 'angular2-google-maps/core' 导入 {MapsAPILoader};
    构造函数(私有mapsAPILoader:MapsAPILoader){


     this.mapsAPILoader.load().then(() => {
            让 autocomplete = new google.maps.places.Autocomplete(this.searchElementRef.nativeElement, {
                类型:[“地址”]
            });
            autocomplete.addListener("place_changed", () => {
                this.ngZone.run(() => {
                    //获取地点结果
                    让地点:google.maps.places.PlaceResult = autocomplete.getPlace();

                    //验证结果
                    if (place.geometry === undefined || place.geometry === null) {
                        返回;
                    }

                    this.latitude = place.geometry.location.lat();
                    this.longitude = place.geometry.location.lng();
                    this.zoom = 12;
                });
            });
    });

}







html页面



    Runtime Error
    No provider for MapsAPILoader!
    Stack
    Error: No provider for MapsAPILoader!
        at injectionError (http://localhost:8103/build/main.js:1655:86)
        at noProviderError (http://localhost:8103/build/main.js:1693:12)
        at ReflectiveInjector_._throwOrNull (http://localhost:8103/build/main.js:3194:19)
        at ReflectiveInjector_._getByKeyDefault (http://localhost:8103/build/main.js:3233:25)
        at ReflectiveInjector_._getByKey (http://localhost:8103/build/main.js:3165:25)
        at ReflectiveInjector_.get (http://localhost:8103/build/main.js:3034:21)
        at AppModuleInjector.NgModuleInjector.get (http://localhost:8103/build/main.js:3981:52)
        at resolveDep (http://localhost:8103/build/main.js:11441:45)
        at createClass (http://localhost:8103/build/main.js:11305:32)
        at createDirectiveInstance (http://localhost:8103/build/main.js:11125:37)

所以..我不知道会发生什么。在哪里找到提供者或我必须放在哪里。

Swa*_*twa 0

改变

import {MapsAPILoader} from 'angular2-google-maps/core';
Run Code Online (Sandbox Code Playgroud)

import {MapsAPILoader} from '@agm/core';
Run Code Online (Sandbox Code Playgroud)