我实际上在搜索用户的位置(至少是地理区域)api,可以使用Angular2打字稿代码轻松使用。
答案 0 :(得分: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());
});
}
}