i get this error message..
Error: Invalid LatLng object: (undefined, undefined)
So I already tried to console.log the "lon" and the "lat" variable to see if the actual value gets outputted, but the output in the console just says “undefined”.. So I guess there is a problem in how I target the values and because of that leaflet gets 2 undefined objects and gives me that error message. Can someone help me target the objects correctly?
My Service to create map markers looks like this
export class CustomersService {
customers: string = '../../assets/data/customerdata.json';
constructor(private http: HttpClient) {}
makeCustomerMarkers(map: L.Map): void {
this.http.get(this.customers).subscribe((res: any) => {
for (const c of res.customerArray) {
const lon: number = c?.customerAdress?.geoCoord?.longitudeCoord;
const lat: number = c?.customerAdress?.geoCoord?.latitudeCoord;
const marker = L.marker([lat, lon]);
marker.addTo(map);
}
});
}
}
This is the component where i call the service
ngAfterViewInit(): void {
this.initMap();
this.customersService.makeCustomerMarkers(this.map);
}
And this is my data
{
"customerArray": [
{
"customerAddress": {
"country": "Deutschland",
"geoCoord": {
"longitudeCoord": 10.4477,
"latitudeCoord": 51.1634
}
},
"phone": "0145221551",
"eMail": "[email protected]",
"homepage": "www.google.de"
},
{
"customerAddress": {
"country": "Deutschland",
"geoCoord": {
"longitudeCoord": 10.4477,
"latitudeCoord": 51.1634
}
},
"phone": "0145221551",
"eMail": "[email protected]",
"homepage": "www.google.de"
},
{
"customerAddress": {
"country": "Deutschland",
"geoCoord": {
"longitudeCoord": 10.4477,
"latitudeCoord": 51.1634
}
},
"phone": "0145221551",
"eMail": "[email protected]",
"homepage": "www.google.de"
}
]
}