2016-11-08 5 views
0

각도 2 베타 18을 사용 중이며 Google지도 지오 코드를 사용하려고합니다. 모든 튜토리얼 설명과 동일하게 수행하고 있지만 이상한 응답이 표시됩니다.각도 2 HTTP가 작동하지 않습니다.

내 구성 요소 :

관찰 가능한 :

import { Injectable } from '@angular/core'; 
import { Http, Response} from '@angular/http'; 
import {Observable} from 'rxjs/Observable'; 

@Injectable() 
export class GoogleMapService { 

    constructor(private http: Http) { } 

convertAddressToCooredinate(address: string){ 
    if(address != null){ 
    var address ="1334 Emerson St, NE Washington DC"; 
    return this.http.get('https://maps.googleapis.com/maps/api/geocode/json?address='+encodeURIComponent(address)) 
        .map(response => response.json()); 
    } 
    } 
} 

응답은 그러나 나는 다음과 같은받을 결과와 JSON을 포함해야 {_isScalar : 거짓, 소스 관측 가능한, 연산자 MapOperator를}

요청을 다른 URL로 보내고 동일한 응답을 받으려고했습니다.

+1

은 어디서 관측에 가입합니까? – echonax

+1

왜 업데이트하지 않습니까? 베타 18은 매우 오래되었습니다. –

+0

@ GünterZöchbauer 아마 내가 잘못 본 것입니다. 일주일 전에 Angular-cli를 사용하여 프로젝트를 만들었습니다. read me 파일에 버전 1.0.0-beta.18이 나와 있습니다. –

답변

1

convertAddressToCooredinate 함수는 관찰 가능을 반환합니다. 코드에서이 관찰 가능 항목을 구독하지 않으면 백엔드에 대한 나머지 호출을하지 않습니다. 그러므로 관찰 대상 만 기록하십시오.

예 :

Some Component 
constructor(private gms: GoogleMapService) { 
    this.gms.convertAddressToCooredinate('some address') 
     .subscribe((response)=>{ 
      console.log(response); 
     }); 
} 
+1

정말 고마워요! –

+0

@DanaEzer 기꺼이 도와 드릴 수 있습니다. – echonax

관련 문제