从X和Y坐标获取纬度和经度

时间:2013-11-08 01:11:06

标签: java javascript processing

似乎有很多关于从经度和纬度转换为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。不过,我很难绕过这个等式。有什么想法吗?

1 个答案:

答案 0 :(得分:2)

好的,基于math @ Wikipedia,我设法扭转了等式

  // 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));

请记住,因为地图的大小,因此我的设计中存在固有因素。我认为它应该是width = 5.47 * FACTOR。