Android - 在自定义地图上绘制GPS坐标 [英] Android - plotting gps coordinate on custom map

查看:232
本文介绍了Android - 在自定义地图上绘制GPS坐标的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在我的应用程序中有一个活动,其中有用作地图的图像。如果图片与谷歌地图网格对齐,那么当我使用地图的左上角和右下角时,我可以从谷歌地图在线获得,然后我可以将用户gps变成屏幕上的x和y。但是,如果地图不是网格对齐,并且其角度超过了数值,我的数学回报会将用户的位置画到屏幕外。显然,我错过了如何处理地图角度的部分,所以如果任何人都可以阐明如何做到这一点,那将是超级有益的。



我知道我将不得不以弧度计算角度并做一些转换,但我不知道从哪里开始。这是我用来得到一个X和Y到目前为止绘制在画布上。

  public double [] getPositionGPS(Location upperLeft,location lowerRight,Location current){

尝试{

double hypotenuse = upperLeft.distanceTo(current);
double bearing = upperLeft.bearingTo(current);
double currentDistanceY = Math.cos(方位* Math.PI / OneEightyDeg)*斜边;
//标记位置的百分比
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;
//标记位置的百分比
double totalHypotenuse2 = upperLeft.distanceTo(lowerRight);
double totalDistanceX = totalHypotenuse2 * Math.sin(upperLeft.bearingTo(lowerRight)* Math.PI / OneEightyDeg);
double currentPixelX = currentDistanceX / totalDistanceX * ImageSizeW;

返回新的double [] {currentPixelX,currentPixelY};

} catch(Exception e){

e.printStackTrace();
返回新的double [] {0,0};



解决方案

是完全错误的,但我认为这是一种获得旋转角度的方法(或者可能是4个角):


  1. 获取角度 alpha 在lowerRight和upperLeft之间。我猜这是等于 180 - lowerRight.bearingTo(upperLeft) 编辑(这个方程应该取决于屏幕的象限)
  2. >
  3. 使用X,Y(屏幕)坐标获得斜边与下边缘之间的角度 theta 。我猜(再次)这个角度的正弦等于:(height)/((height ^ 2)+(width ^ 2))^ 1/2

  4. 现在旋转角度等于 theta - alpha

  5. ol>

    如果您想要显示此内容:


    I have an activity in my app where there are images I use as maps. If the image is "grid aligned" to google maps then when I use the top left and bottom right corners of the map I get from googlemaps online then I can turn the users gps into an x and y on screen. However if the map is not "grid aligned" and is at an angle than the values my math returns draws the users position off screen. Obviously I am missing the part on how to handle the angle of the map so if anyone could shed some light on how to do that it would be super helpfull.

    I know I would have to figure out the angle in radians and do some conversion but I have no idea where to start. This is what I use to get an x and y to plot on a canvas so far.

    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};
    
        }
    

    解决方案

    I might be completely wrong but I think this is a way to get the angle of rotation (or maybe the 4 corners):

    1. Get the angle alpha between lowerRight and upperLeft. I guess this is equal 180 - lowerRight.bearingTo(upperLeft) EDIT (This equation should be dependent on the quadrant of the screen)
    2. Use your X,Y (screen) coordinates to get the angle theta between the hypotenuse and the lower edge. I guess (again) the sine of this angle is equal to: (height) / ((height^2) + (width^2))^1/2
    3. Now the angle of rotation is equal to theta - alpha

    If you want to visualize this:

    这篇关于Android - 在自定义地图上绘制GPS坐标的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆