2016-05-14 70 views

回答

0
import { Injectable} from '@angular/core'; 
import { Observable } from 'rxjs/Observable'; 
import {Http} from '@angular/http'; 
import 'rxjs/Rx'; 

@Injectable() 
export class CurrentLocationService { 

    constructor(private _http: Http) {} 

    getCurrentLocation(): Observable<any> { 
     return this._http.get('http://ipinfo.io/json?callback=JSON_CALLBACK') 
     .map(response => response.json()) 
     .catch(error => { 
      console.log(error); 
      return Observable.throw(error.json()); 
     }); 
    } 
} 
相關問題