Google maps 如何将cordova GoogleMap分配给Ionic 4中的java脚本映射位置服务方法?

Google maps 如何将cordova GoogleMap分配给Ionic 4中的java脚本映射位置服务方法?,google-maps,cordova-plugins,ionic4,google-places,Google Maps,Cordova Plugins,Ionic4,Google Places,我在爱奥尼亚4中使用谷歌地图cordova插件,它工作正常。 但是,当我试图在typeScript中安装GoogleMaps功能以更好地工作时,我无法将map对象传递给Google.map.place.placesService() 当我像这样使用placesService时: this.placesService = new google.maps.places.PlacesService(this.map); 它起作用了。但是当我为typescript安装GoogleMap并删除=>Var

我在爱奥尼亚4中使用谷歌地图cordova插件,它工作正常。 但是,当我试图在typeScript中安装GoogleMaps功能以更好地工作时,我无法将map对象传递给Google.map.place.placesService()

当我像这样使用placesService时:

this.placesService = new google.maps.places.PlacesService(this.map);
它起作用了。但是当我为typescript安装GoogleMap并删除=>VarGoogle的声明时

npm install @types/google-maps --save
我得到了这个错误:

Argument of type 'GoogleMap' is not assignable to parameter of type 'HTMLDivElement | Map<Element>'.
类型为“GoogleMap”的参数不能分配给类型为“HtmlLevel | Map”的参数。

placesServices不接受此.map。

您可以使用本教程,这可能会对您有所帮助


https://medium.com/ramsatt/integrate-google-maps-on-ionic-4-beta-application-37497dbc12e3

我删除了PlacesService,然后将完整地址从autoComplete传递到Google.geoCode

加载地图后:

async loadMap(){
    ...
    this.autocompleteService = new google.maps.places.AutocompleteService();
}

searchPlace() {
    let config = {
        types: ['geocode'],
        input: this.query
    }

    this.autocompleteService.getPlacePredictions(config, (predictions, status) => {
      if (status === google.maps.places.PlacesServiceStatus.OK && predictions) {

          this.places = [];

          predictions.forEach((prediction) => {
              this.places.push(prediction);
          });
      }
    });
最后我通过这个方法得到了地理代码:

getCoder(place: any) {

    this.places = [];

    const options: GeocoderRequest = {
      address: place.description
    };

    // Address -> latitude,longitude
    Geocoder.geocode(options).then((results: GeocoderResult[]) => {
      console.log(results);
      this.map.setCameraTarget(results[0].position);
    });
}

从html页面:

<ion-searchbar [(ngModel)]="query" (ionInput)="searchPlace()"></ion-searchbar>


通过PlaceService,我们有PlaceID,但通过地理编码,我想(我不确定)我们必须再次获得地址。

谢谢,它没有使用cordova提供的Google地图,从他们的文档中我看到PlaceService不支持它
<ion-searchbar [(ngModel)]="query" (ionInput)="searchPlace()"></ion-searchbar>