Get latitude and longitude from X and Y coordinates

后端 未结 1 1457
走了就别回头了
走了就别回头了 2021-01-15 18:32

It seems that there is a wealth of knowledge on converting from Longitude and Latitude to X and Y coordinates, but not the reverse.

Here is a function of mine based

相关标签:
1条回答
  • 2021-01-15 19:08

    Ok based on the math @ Wikipedia, I managed to reverse the equation

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

    Just remember that FACTOR is something inherent in my design, because of the size of my map. I believe it should be width = 5.47 * FACTOR.

    0 讨论(0)
提交回复
热议问题