Reach Fetching Datas from external API

Hi guys, I got a small problem.
I would like to get with an external API some json datas but there is a trap.

"weather":[{"id":801,"main":"Clouds","description":"few clouds","icon":"02d"}],

That’s the json data of a small weather API but i don’t even know how to get precisely a object like in Coord -> lon.

In my code I put :

		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; = resp.coords.latitude;
			this.test = this.Pro.getWeatherPerLatLng(,this.lng).subscribe((data: Weather) => = {lon: data["lon"],
			console.log(this.test, 'Sortie de la fonction');
			console.log('Weather Object',;

But i don’t know how to get the “LON” in '‘Coord’…

I created an interface like that

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

Thanks for your time …


Hi, thanks for your reply but if i’m doing a parse, shoud I delete the line with the subscribe ?

JSON data is normally accessed in Javascript through dot notation.


1 Like

Yes i do but always saying “Unable to assign type {lon: any} to type number”
I think i’m doing it really wrong…