将笛卡尔(X,Y)转换为坐标GPS(纬度和经度) [英] Convert Cartesian (X,Y) to coordinates GPS (Latitude & Longitude)
问题描述
我需要将坐标X,Y转换为纬度和经度.我已经阅读了维基百科地图投影,类似的stackoverflow论坛,应用了我的自定义解决方案,但仍然无法正常工作.
I need to convert coordinates X, Y into Latitude and Longitude. I've read wikipedia map projections, similar stackoverflow forums, applied my custom solutions and still didn't work.
我从公式中获得的坐标是错误的,经度是可以接受的,但纬度是不可接受的.我看不出我的计算错误在哪里.
The coordinates I get from my formula are wrong, Longitude is acceptable but Latitude is not. I don't see where my calculous is wrong.
X,Y点是从JLayeredPane中获取的,其背景地图图像的大小,一旦在该地图图像上释放了较小的图像后,
The X,Y Point is taken from a JLayeredPane with the size of a background Map image, once a smaller image is released on this Map image, the point is taken.
public void mouseReleased(MouseEvent e) {
DM.setUpCoordinates(layeredPane.getComponent(index-1).getLocation());
}
在此之后,我试图正确计算纬度和经度投影.我拥有的数据是:
After this, I'm trying to correctly calculate the Latitude and Longitude projection. The data I own is:
- 地图上的X,Y坐标
- 地图的总宽度和高度
- 地图居中的经纬度
到目前为止我尝试过的内容:
What I have tryied so far:
尝试等角投影
public void setUpCoordinates(Point p) {
//Equirectangular projection: optimal for small streets
Long = ((p.getX())/(6371000*Math.cos(MG.getLati())))+MG.getLongi();
Lat = (((p.getY())/6371000)+MG.getLati());
}
I also tryied to implement the Mercator projection from this link with very little to no success at all.
我知道我没有在公式中使用地图上的总宽度和高度,这可能是错误,但是我不知道如何使用它!
I am aware I'm not using total width and height from the Map on my formulas and this might be the error, but I don't know how to use it!
对如何从(x,y)转换为(纬度,经度)有帮助吗?
any help how to convert from (x,y) to (latitude, longitude)?
谢谢
推荐答案
您需要按中心位置移动像素坐标,还需要使用地图比例尺-经度和纬度范围(我假设伸长率 Math.cos(MG.getLati())
系数以经度比例表示)
You need to shift pixel coordinates by center position and also use map scale - longitude and latitude range (I assume that elongation Math.cos(MG.getLati())
coefficient is accounted in longitude scale)
Long = (p.getX() - MapWidth/2)*LongitudeRange/MapWidth +MG.getLongi();
Lat = (p.getY() - MapHeight/2)*LatitudeRange/MapHeight + MG.getLati());
这篇关于将笛卡尔(X,Y)转换为坐标GPS(纬度和经度)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!