Я работаю над небольшим приложением, чтобы лучше узнать 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'] (который не работал ..)?
Спасибо за ваше время:)