ERROR TypeError: Cannot read property 'latitude' of undefined

Bonjour,

j’aimerais utiliser l’API de google pour afficher la carte de geolocalisation mais je reçcois l’erreur suivante:

voilà le code:
page.html

<ion-header [translucent]=“true”>





Détails locations


Title : {{currentPlace.title}} City : {{currentPlace.city}} Country : {{currentPlace.country}} Keywords : {{currentPlace.keyword}}

model.ts

export interface Place{
title:string;
city?:string;
country?:string;
keyword?:string;
selected?:boolean;
timestamp?:number;
photos?:string;
coodinates?:{
latitude:number;
longitude:number;
};

}

merci d’avance

I don’t see where currentPlace is declared, but I’m guessing you didn’t bother initializing it. Always initialize every property that is referenced from a template, even if it is just to an empty dummy like {} or [].

Bonjour,

effectivement je n’ai pas posté tout le code.
j’ai déclaré comme suit:

import { Component, OnInit } from ‘@angular/core’;
import {LocationsService} from ‘…/services/locations.service’;
import {Place} from ‘…/model/place.model’;

@Component({
selector: ‘app-location-details’,
templateUrl: ‘./location-details.page.html’,
styleUrls: [’./location-details.page.scss’],
})
export class LocationDetailsPage implements OnInit {
private currentPlace: Place;

constructor(private locService:LocationsService) { }

ngOnInit() {
this.currentPlace=this.locService.currentLocation;
}

}

par ailleurs, comment je vais initialiser?
merci

currentPlace may not be private. Any property accessed by templates must be public. Additionally, yes, you must move your initialization of currentPlace to the constructor. ngOnInit is too late.

Bonjour,

merci beaucoup d’avoir pris le temps de me repondre. Cependant, meme si j’ai change currentPlace en Public aussi l’erreur persiste toujours.
pourtant je suivais un tuto fidelement.

Merci