我正在开发一款小应用程序来学习更好的IONIC。 但是当我调用http.get时,我遇到了一个很大的问题。 这是json中请求的响应。
{
"coord":{"lon":-73.57,"lat":45.5},
"weather":[{"id":801,"main":"Clouds","description":"few clouds","icon":"02d"}],
"base":"stations","main":{"temp":22.91,"pressure":1010,"humidity":60,"temp_min":22,"temp_max":24},
"visibility":48279,
"wind":{"speed":7.7,"deg":270,"gust":11.3},
"clouds":{"all":20},
"dt":1526320800,
sys":"type":1,"id":3829,"message":0.0902,"country":"CA",
"sunrise":1526289839,"sunset":1526343480},
id":6077243,
"name":"Montreal","cod":200}
这是我的代码,我想像Coord.lat& Coord.lon在屏幕上显示它,还有天气等。
loadPosition(){
this.geolocation.getCurrentPosition().then((resp) => {
// resp.coords.latitude
//let userPosition: LatLng = news LatLng(resp.coords.latitude,resp.coords.longitude);
//console.log(resp.coords.latitude + ' ' + resp.coords.longitude);\
this.lng = resp.coords.longitude;
this.lat = resp.coords.latitude;
this.test = this.Pro.getWeatherPerLatLng(this.lat,this.lng).subscribe((data: Weather) => this.weather.coord.lon = {lon:data['lon']
});
console.log(this.test, 'Sortie de la fonction');
console.log('Weather Object', this.weather);
});
}
使用这个小界面:
export interface Weather{
coord: {
lon: number,
lat: number
},
weather: [
{
id: number,
main: String,
description: String,
icon: String
}
],
base: String,
main: {
temp: number,
pressure: number,
humidity: number,
temp_min: number,
temp_max: number
},
visibility: number,
wind: {
speed: number,
deg: number
},
clouds: {
all: number
},
dt: number,
sys: {
type: number,
id: number,
message: number,
country: String,
sunrise: number,
sunset: number
},
id: number,
name: String,
cod: number
}
是否有任何解决方案'自动实现'我所做的界面或我必须做多个 .subscribe((data:Weather)=> this.weather.coord.lon = {lon:data [ 'lon'] (哪个不起作用..)?
感谢您的时间:)