我在我的应用程序中有一个活动,在其中使用作为地图的图像。如果图像与Google地图“网格对齐”,那么当我使用从在线Google Maps获取的地图左上和右下角时,我可以将用户GPS转换为屏幕上的x和y。然而,如果地图不是“网格对齐”的,而是处于倾斜状态,那么我的数学计算返回的值会绘制用户位置超出屏幕。显然,我缺少处理地图角度的部分,因此如果有人能够提供一些关于如何处理这个问题的帮助,那将非常有用。
我知道我需要计算弧度并进行一些转换,但我不知道从哪里开始。到目前为止,这就是我用来绘制画布上的x和y的情况。
我知道我需要计算弧度并进行一些转换,但我不知道从哪里开始。到目前为止,这就是我用来绘制画布上的x和y的情况。
public double[] getPositionGPS(Location upperLeft, Location lowerRight, Location current){
try{
double hypotenuse = upperLeft.distanceTo(current);
double bearing = upperLeft.bearingTo(current);
double currentDistanceY = Math.cos(bearing * Math.PI / OneEightyDeg) * hypotenuse;
// "percentage to mark the position"
double totalHypotenuse = upperLeft.distanceTo(lowerRight);
double totalDistanceY = totalHypotenuse * Math.cos(upperLeft.bearingTo(lowerRight) * Math.PI / OneEightyDeg);
double currentPixelY = currentDistanceY / totalDistanceY * ImageSizeH;
double hypotenuse2 = upperLeft.distanceTo(current);
double bearing2 = upperLeft.bearingTo(current);
double currentDistanceX = Math.sin(bearing2 * Math.PI / OneEightyDeg) * hypotenuse2;
// "percentage to mark the position"
double totalHypotenuse2 = upperLeft.distanceTo(lowerRight);
double totalDistanceX = totalHypotenuse2 * Math.sin(upperLeft.bearingTo(lowerRight) * Math.PI / OneEightyDeg);
double currentPixelX = currentDistanceX / totalDistanceX * ImageSizeW;
return new double[]{currentPixelX, currentPixelY};
}catch(Exception e){
e.printStackTrace();
return new double[]{0,0};
}