You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何引用对象内存储的对象?飞机位置坐标提取技术求助

Troubleshooting Lat/Lon Extraction from Leaflet LatLng Object

Let's work through this issue—you're just a couple of small fixes away from getting the coordinates you need!

First, let's spot the most obvious mistake: you have a typo in your variable name. You assigned the position to aircraft.currentPosition, but when trying to extract the latitude, you wrote aircraft.currentPositon (missing an i in "Position"). That's why you're not getting any data—you're trying to access a property that doesn't exist.

Second, Leaflet's L.latLng object stores longitude under the lng property, not lon. Even if you fixed the typo, using .lon would still fail because that's not the correct property name for Leaflet's LatLng instances.

Correct Code Examples

Here's how you should extract the coordinates properly:

Using Property Access

// Fix the typo and use Leaflet's correct property names
const lat = aircraft.currentPosition.lat;
const lng = aircraft.currentPosition.lng; // Use lng instead of lon

Using Method Calls (Alternative)

Leaflet's LatLng object also provides getter methods if you prefer that approach:

const lat = aircraft.currentPosition.lat();
const lng = aircraft.currentPosition.lng();

Quick Debug Tip

If you're still having issues, add a console log to verify what aircraft.currentPosition actually contains:

console.log(aircraft.currentPosition);

This should show you a Leaflet LatLng object with lat and lng properties (or methods) if your initial assignment worked correctly. If it logs undefined, double-check that posUpdate.record[i].lat and posUpdate.record[i].lon have valid values when you assign them.

内容的提问来源于stack exchange,提问作者cpeddie

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.21 08:41:36