错误:TypeError:_this._objectInstance.remove不是函数

时间:2017-12-15 13:22:53

标签: angular google-maps ionic-framework ionic2

我是离子应用程序开发的初学者。
我从API纬度和经度得到响应,我将它传递到谷歌地图,将标记放在地图中。但我得到错误

  

错误:TypeError:_this._objectInstance.remove不是函数。

这是类型脚本代码

 getLocation(item){

    console.log(item.Street);

    var headers = new Headers();
    headers.append('Content-Type', 'application/json' );
    headers.append("Accept", 'application/json');
    let options = new RequestOptions({ headers: headers });

    let postParams = {
      Street: "fortesting",
      City: "string",
      zipORpincode: "string",
      DistrictORcounty: "string",
      State: "string",
      Country: "string"
    }

   this.http.post('http://link of an API',postParams, options)
      .subscribe(
        res => {

          let dataTemp = res.json(); //dataTemp is the json object you showed me
          this.Longitude = dataTemp.Longitude; //contains a [] object with all yours users
          this.Latitude = dataTemp.Latitude;
          console.log(this.Longitude);//This is for log 
          console.log(this.Latitude );//This is for log 

          let mapOptions: GoogleMapOptions = {
            camera: {
              target: {
                lat: this.Latitude,
                lng: this.Longitude 
              },
              zoom: 18,
              tilt: 30
            }
          };

          this.map = GoogleMaps.create('map_canvas', mapOptions);

          // Wait the MAP_READY before using any methods.
          this.map.one(GoogleMapsEvent.MAP_READY)
            .then(() => {
              console.log('Map is ready!');

              // Now you can use all methods safely.
              this.map.addMarker({
                  title: 'Ionic',
                  icon: 'blue',
                  animation: 'DROP',
                  position: {
                    lat: this.Latitude,
                    lng: this.Longitude 
                  }
                })
                .then(marker => {
                  marker.on(GoogleMapsEvent.MARKER_CLICK)
                    .subscribe(() => {
                      alert('clicked');
                    });
                });

            });              

        },
        err => {
          console.log(err);
        }
      );   
  }

这是我正在调用函数的HTML代码

 <button ion-button block menuToggle="right" color="menu-o" 
                (click)='getLocation(results)'>
                        <div>
                            <ion-icon name="create"></ion-icon>
                            <label>Get Location</label>
                        </div>
                </button>

1 个答案:

答案 0 :(得分:0)

假设map_canvas是您需要创建地图的HTML元素的ID,您需要将该元素传递给create函数而不仅仅是id。

您可以使用ViewChild引用它。

声明一个类变量

@ViewChild('map_canvas') mapElement;

发送原生元素

      this.map = GoogleMaps.create(this.mapElement.nativeElement, mapOptions);

Github issue

建议的来源:@Faisalali23解决方案