如何绘制用作地图的图像上的GPS位置? [英] How to plot a GPS location on an image being used as a map?

查看:227
本文介绍了如何绘制用作地图的图像上的GPS位置?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有我需要用作应用程序地图的商场图片。我有地图底角的GPS lat / long,我计算出了从底部GPS坐标到地图图像顶部的距离。这些都不是直线上下的线性地图,这意味着我不能只画出我的经纬度,长得很好,很整齐。

我尝试过使用各种公式,而且我非常接近,但是我无法绘制地图左上角和右上角的顶部经纬度。到目前为止,这是我的:

  double distanceFromLeftToRightGPS = bottomLeft.distanceTo(bottomRight); 
double bearingleftToRight = bottomLeft.bearingTo(bottomRight);

double distmapFromLeftToRightImg = map.getWidth();
double distmapFromTopToBottomImg = map.getHeight();

double percentValueOfTopToBottomImg =(distmapFromTopToBottomImg * 100)
/ distmapFromLeftToRightImg;
double distanceFromTopToBottomGPS =(percentageValueOfTopToBottomImg * 0.01)
* distanceFromLeftToRightGPS;

double bearingToTopFromBottom = -90;
double lat1 = Math.toRadians(bottomLeft.getLatitude());
double lon1 = Math.toRadians(bottomLeft.getLongitude());

double dist =(distanceFromTopToBottomGPS / 1000f)/6371.0f;

double lat2 = Math.asin(Math.sin(lat1)* Math.cos(dist)
+ Math.cos(lat1)* Math.sin(dist)* Math.cos (bearingToTopFromBottom));

double a = Math.atan2(Math.sin(bearingToTopFromBottom)* Math.sin(dist)
* Math.cos(lat1),Math.cos(dist) - Math.sin (lat1)* Math.sin(lat2));

System.out.println(a =+ a);
double lon2 = lon1 + a;

lon2 =(lon2 + 3 * Math.PI)%(2 * Math.PI) - Math.PI;

System.out.println(Latitude =+ Math.toDegrees(lat2)+\\\
Longitude =
+ Math.toDegrees(lon2));

这让我如此接近,但最终的位置离开了真正的位置。我也不确定我应该使用什么样的方式来查看地图底部会发生什么。如果其他人有关于如何获得这个工作的信息,那将是非常棒的。

解决方案

这两个方法的解决方案I在SO上从其他一些帖子中提出。如果您的地图的左上角和右下角有一个左上角的GPS坐标和右下角的GPS坐标,则使用这两种方法可以确定在地图上绘制第三个GPS坐标的位置。这些将与您的左上角和右下角的GPS坐标一样敏捷。然后我使用画布在位图上绘制第三点。

  public final double double OneEightyDeg = 180.0d; 
public static double ImageSizeW,ImageSizeH;

getSizesFromBitmap(ImageSizeW,ImageSizeH);


public double getCurrentPixelY(位置upperLeft,位置lowerRight,位置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;

返回currentPixelY;
}

public double getCurrentPixelX(Location upperLeft,location lowerRight,Location current){
double hypotenuse = upperLeft.distanceTo(current);
double bearing = upperLeft.bearingTo(current);
double currentDistanceX = Math.sin(方位* Math.PI / OneEightyDeg)*斜边;
//标记位置的百分比
double totalHypotenuse = upperLeft.distanceTo(lowerRight);
double totalDistanceX = totalHypotenuse * Math.sin(upperLeft.bearingTo(lowerRight)* Math.PI / OneEightyDeg);
double currentPixelX = currentDistanceX / totalDistanceX * ImageSizeW;

return currentPixelX;
}


I have images of malls that I need to use as maps for an app I am making. I have the GPS lat/long of the bottom corners of the map and I figured out the distance from the bottom GPS coordinates to what would be the top of the map image. How ever these are not straight up and down linear maps meaning I can't just plot my lat and long all nice and neat.

I've tried using various formulas and I'm so close but I can't plot the top lat and long of the top left and right of the map. So far this is what I have:

double distanceFromLeftToRightGPS = bottomLeft.distanceTo(bottomRight);
double bearingleftToRight= bottomLeft.bearingTo(bottomRight);

double distmapFromLeftToRightImg = map.getWidth();
double distmapFromTopToBottomImg = map.getHeight();

double percentageValueOfTopToBottomImg = (distmapFromTopToBottomImg * 100)
        / distmapFromLeftToRightImg;
double distanceFromTopToBottomGPS = (percentageValueOfTopToBottomImg * 0.01)
        * distanceFromLeftToRightGPS;

double bearingToTopFromBottom = -90;
double lat1 = Math.toRadians(bottomLeft.getLatitude());
double lon1 = Math.toRadians(bottomLeft.getLongitude());

double dist = (distanceFromTopToBottomGPS/1000f)/6371.0f;

double lat2 = Math.asin(Math.sin(lat1) * Math.cos(dist)
        + Math.cos(lat1) * Math.sin(dist) * Math.cos(bearingToTopFromBottom));

double a = Math.atan2(Math.sin(bearingToTopFromBottom) * Math.sin(dist)
        * Math.cos(lat1), Math.cos(dist) - Math.sin(lat1) * Math.sin(lat2));

System.out.println("a = " +  a);
double lon2 = lon1 + a;

lon2 = (lon2 + 3 * Math.PI) % (2 * Math.PI) - Math.PI;

System.out.println("Latitude = " + Math.toDegrees(lat2) + "\nLongitude = "
        + Math.toDegrees(lon2));

This gets me oh so close but the end location is off from where it really should be. I'm also not sure what bearing I should be using to look to what would be up from the bottom of the map. If anyone else has some info on how to get this to work that would be awesome.

解决方案

These two methods where the solution I came up with from some other posts here on SO. If you have a top left GPS coord and a bottom right GPS coord for the top left and bottom right corners of your map then using these two methods you can figure out where to draw your third GPS coord on the map. These will be as acurate as your top left and bottom right GPS coords are. I then draw the third point on the bitmap using a canvas.

public final static double OneEightyDeg = 180.0d;
public static double ImageSizeW, ImageSizeH ;

getSizesFromBitmap(ImageSizeW, ImageSizeH);


public double getCurrentPixelY(Location upperLeft, Location lowerRight, Location current) {
    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;

    return currentPixelY;
}

public double getCurrentPixelX(Location upperLeft, Location lowerRight, Location current) {
    double hypotenuse = upperLeft.distanceTo(current);
    double bearing = upperLeft.bearingTo(current);
    double currentDistanceX = Math.sin(bearing * Math.PI / OneEightyDeg) * hypotenuse;
    //                           "percentage to mark the position"
    double totalHypotenuse = upperLeft.distanceTo(lowerRight);
    double totalDistanceX = totalHypotenuse * Math.sin(upperLeft.bearingTo(lowerRight) * Math.PI / OneEightyDeg);
    double currentPixelX = currentDistanceX / totalDistanceX * ImageSizeW;

    return currentPixelX;
}

这篇关于如何绘制用作地图的图像上的GPS位置?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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