0

I am using Angular 2 beta.18, and trying to use google map geocode. I am doing the same as all tutorial describe, but I receive a strange response.

My component:

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

The response should contain a JSON with results, however I recieve the following:

Observable {_isScalar: false, source: Observable, operator: MapOperator}

I tried directing the request to other URLs and receive the same response.

Dana Ezer
  • 61
  • 7

1 Answers1

1

Your convertAddressToCooredinate function returns an observable. If you don't subscribe to this observable in your code, you won't make a rest call to your backend. Hence you log only your observable.

Example:

Some Component
constructor(private gms: GoogleMapService ) { 
    this.gms.convertAddressToCooredinate('some address')
        .subscribe((response)=>{
            console.log(response);
        });
}
eko
  • 39,722
  • 10
  • 72
  • 98