如何将经纬度转换为Google Earth的度数格式?

问题描述:

我对端口列表有纬度/经度坐标.坐标为2856N 05211E格式(将这些数字总计,顺便说一句).我试图弄清楚如何将它们转换为Google Earth插件使用的度数格式,以便在地图上绘制它们. API中是否有可用于转换此参数的参数?任何想法,将不胜感激.

I have lat/long coordinates for a list of ports. The coordinates are in a 2856N 05211E format (totally made those numbers up, btw). I'm trying to figure out how I can convert them to the degree format the Google Earth pluginuses in order to plot them on a map. Is there a parameter in the API that I could use to convert this? Any ideas would be appreciated.

我假设您可以自己解析这些值.如果没有,请提供您要使用的语言.

I'm assuming you can parse the values yourself. If not, then provide the language you wish to use.

转换很简单,度/分/秒(DMS)到小数度是

The conversion is simple, Degrees/Min/Sec(DMS) to Decimal Degrees is

result = D + M/60 + S/3600;

如果是S或W,

result *= -1;

一如既往,进行您自己的错误检查.

As always, do your own error checking.

-90< =纬度< = 90

-90 <= lat <= 90

-180< = lon< = 180

-180 <= lon <= 180