【发布时间】:2022-02-23 10:03:27
【问题描述】:
我收到此错误消息..
错误:无效的 LatLng 对象:(未定义,未定义)
所以我已经尝试控制台记录“lon”和“lat”变量以查看是否输出了实际值,但控制台中的输出只是显示“未定义”.. 所以我猜有问题在我如何定位这些值时,由于该传单获得了 2 个未定义的对象并给了我该错误消息。有人可以帮我正确定位对象吗?
我创建地图标记的服务如下所示
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);
}
});
}
}
这是我调用服务的组件
ngAfterViewInit(): void {
this.initMap();
this.customersService.makeCustomerMarkers(this.map);
}
这是我的数据
{
"customerArray": [
{
"customerAddress": {
"country": "Deutschland",
"geoCoord": {
"longitudeCoord": 10.4477,
"latitudeCoord": 51.1634
}
},
"phone": "0145221551",
"eMail": "test@trashmail.de",
"homepage": "www.google.de"
},
{
"customerAddress": {
"country": "Deutschland",
"geoCoord": {
"longitudeCoord": 10.4477,
"latitudeCoord": 51.1634
}
},
"phone": "0145221551",
"eMail": "test@trashmail.de",
"homepage": "www.google.de"
},
{
"customerAddress": {
"country": "Deutschland",
"geoCoord": {
"longitudeCoord": 10.4477,
"latitudeCoord": 51.1634
}
},
"phone": "0145221551",
"eMail": "test@trashmail.de",
"homepage": "www.google.de"
}
]
}
【问题讨论】:
标签: angular typescript leaflet