4 .net c# mapping latitude-longitude
我正在尝试使用墨卡托投影计算地图上的 Y 位置,并给出纬度(以度为单位)。这是我需要的:
//mapHeight might be 600 (pixels), for example
//latitudeInDegrees ranges from -90 to 90
public double CalculateY(double mapHeight, double latitudeInDegrees)
{
//what on earth do I do here to calculate the Y offset on the map?
return ???;
}
Run Code Online (Sandbox Code Playgroud)
我尝试了在网上找到的各种方法(包括维基百科和 stackoverflow),但没有一个对我有用。我可能在做一些愚蠢的事情,但我不知道是什么。谁能拯救我的理智?
public double CalculateY(double mapHeight, double latitudeInDegrees)\n{\n return Math.Log(Math.Tan(latitudeInDegrees / 360d * Math.PI + Math.PI / 4));\n}\nRun Code Online (Sandbox Code Playgroud)\n\n不记得比例 y 与 mapHeight (你应该知道 latitudeInDegrees 的最大值和最小值)
\n\n引用维基百科:
\n\n\n\n\n在北纬度或南纬度高于 70\xc2\xb0 的地区,墨卡托投影实际上无法使用。
\n
你应该写这样的代码:
\n\nprivate double CalculateYRelative(double latitudeInDegrees)\n{\n return Math.Log(Math.Tan(latitudeInDegrees / 360d * Math.PI + Math.PI / 4));\n}\n...\nminY = CalculateYRelative(MinLatitudeInDegrees);\nmaxY = CalculateYRelative(MaxLatitudeInDegrees);\n...\npublic double CalculateY(double mapHeight, double latitudeInDegrees)\n{\n return mapHeight*\n (CalculateYRelative(latitudeInDegrees) - minY) / (maxY - minY);\n}\nRun Code Online (Sandbox Code Playgroud)\n\n了解更多信息:
\n\n\n\n\n\n\n