0
我实际上是在搜索用户的位置(至少是地理区域)的API,可以很容易地使用Angular2打字稿代码。如何在Angular2中读取用户当前的地理区域?
我实际上是在搜索用户的位置(至少是地理区域)的API,可以很容易地使用Angular2打字稿代码。如何在Angular2中读取用户当前的地理区域?
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());
});
}
}
你有没有检查过如何在JS中做到这一点?这在Angular中是一样的;-) –