首页 > 解决方案 > 将国家坐标映射到暂停的屏幕像素

问题描述

我有拉脱维亚三个城市的坐标

57.4093885,21.5246563

56.9713962,23.9890814

55.8958226,26.4671762

我需要把它们放在我的拉脱维亚地图上。我无法理解算法,因为它放在我的地图上。我可以使用什么算法将纬度和经度转换为地图上的点。

我的地图

标签: algorithmmathcoordinateslatitude-longitude

解决方案


对于 Merkator,投影映射相当简单。

地图有边界坐标 - LatMin, LonMin, Lattin, LonMax。它对应于坐标为 0、0、Width、Height 的屏幕矩形。

经度有线性映射

X = Width * (Lon - LonMin) / (LonMax- LonMin)

纬度应该用一些数学计算:

 a = 6378137    //geo-ellipsoid parameters
 b = 6356752.31
 f=(a-b)/a
 e=sqrt(2*f-f^2)  //excentricitet
 YY = a * ln(Tan(pi / 4 + Lat / 2) * 
     ((1 - e * sin(Lat)) / (1 + e * sin(Lat)))**(e/2)); 

更简单,不太精确的版本:

 YY = a * ln(Tan(pi / 4 + Lat / 2))

为 LatMin、LatMax、城市纬度 Lat 查找 YY,并应用类似的线性插值

 Y = Height * (YY_Lat - YY_LonMin) / (YY_LonMax- YY_LonMin)

推荐阅读