从X和Y坐标中获取纬度和经度[英] Get latitude and longitude from X and Y coordinates

问题描述

似乎有很多关于从经度和纬度转换为 X 和 Y 坐标的知识,但反之则不然.

这是我的一个基于 Kavrayskiy 数学的函数

  float xp = kavraX(radians(pv.x), radians(pv.y))*FACTOR;
  float yp = kavraY(radians(pv.x), radians(pv.y))*FACTOR;

// mapping -- this gives you screen X and Y coords from LAT and LONG
float kavraX (float latitude, float longitude) // Kavra for Kavrayskiy 
// formula from http://en.wikipedia.org/wiki/Kavrayskiy_VII_projection
{
  return ((3 * longitude) / TWO_PI)*sqrt(pow(PI, 2)/3 - pow(latitude, 2));
} 

float kavraY (float latitude, float longitude) 
{
  return latitude*-1;
} 

在这种情况下,pv.x 可能只是 34(对于 LA),在这种情况下,pv.y 将是 -118.不过,我很难扭转这个等式.有什么想法吗?

推荐答案

好的,根据@维基百科的数学,我设法扭转了方程式

  // find latitude from Y coord
    // height / 2 to make middle of map ZERO, *-1 to flip it, so south of equator is negative.
    // divide by FACTOR to make it fit within bounds of larger map
  float reMapY = ((mouseY - (height/2))*-1)/FACTOR;
  println(degrees(reMapY));

  // I have no idea what I'm doing
  float temp = sqrt((pow(PI,2)/3 - pow(reMapY,2)));
  float reMapX = (mouseX - (width/2))/FACTOR;
  float temp2 = ((reMapX / temp) * TWO_PI) / 3;
  println(degrees(temp2));

请记住,FACTOR 是我设计中固有的东西,因为我的地图很大.我相信它应该是宽度 = 5.47 * FACTOR.

本文地址:https://www.itbaoku.cn/post/978608.html