2017-12-15 17 views
1

저는이 분야의 응용 프로그램 개발에 초보자입니다.
API 위도와 경도로부터 응답을 받고 있는데,이를 Google지도에 전달하여지도에 표식을 배치합니다. 하지만 난 오류오류 : TypeError : _this._objectInstance.remove가 함수가 아닙니다.

ERROR: TypeError: _this._objectInstance.remove is not a function.

에게이 유형의 스크립트 코드

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); 
     } 
    ); 
    } 

을 얻고이 map_canvas 가정

<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> 
+0

에 의해 제안? –

+0

이 코드 조각은 괜찮습니다. 오류는 'remove' 함수를 호출하는 구성 요소에서 비롯됩니다. 대신 찾을 수 있을까요? – trichetriche

+0

코드에서 remove 함수를 사용하지 않았습니다. – Bala

답변

0

의 ID입니다 HTML 코드있는 내가 부르고 기능입니다 맵을 작성해야하는 HTML 요소가 있으면, id뿐만 아니라 작성 기능으로 요소를 전달해야합니다.

ViewChild을 사용하여 참조 할 수 있습니다.

변수 클래스

@ViewChild('map_canvas') mapElement; 

를 선언 보내기 기본 요소

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

출처 : Github issue 솔루션은 어디에서 당신은`제거`메서드를 호출 할 @Faisalali23