Jam*_*kis 7 gps android android-canvas
我的应用程序中有一个活动,其中有我用作地图的图像.如果图像与Google地图"网格对齐",那么当我使用地图的左上角和右下角时,我会从googlemaps在线获取,然后我可以将用户gps转换为屏幕上的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};
}
Run Code Online (Sandbox Code Playgroud)
我可能完全错了,但我认为这是一种获取旋转角度(或者可能是 4 个角)的方法:
180 - lowerRight.bearingTo(upperLeft) 编辑(这个方程应该取决于屏幕的象限)(height) / ((height^2) + (width^2))^1/2theta - alpha如果你想形象化这一点:

| 归档时间: |
|
| 查看次数: |
2112 次 |
| 最近记录: |