android - 转换 GPS 坐标以匹配自定义 2d 户外布局图像

标签 android flutter google-maps math gps

我不知道这是否可能,但我正在尝试拍摄自定义户外足球场布局的图像并让球员的GPS坐标对应图像xy位置。这样,可以通过应用程序查看球员在球场上的当前位置,作为一种实时跟踪。
我也看过这个Convert GPS coordinates to coordinate plane .问题是我不知道这是否可行并且想事先确认。帖子中提供的图片用于室内定位,来自 11几年前。
我用了LocationGoogle Maps flutter 的包。玩家的latitudelongitude对应实际latitudelongitude android studio中的模拟器在测试时显示。
有问题的布局以及与我正在寻找的结果的密切比较。
enter image description here
对此问题的任何帮助将不胜感激,并提前感谢所有帮助。
编辑:
在查看了更多内容后,我尝试了这篇文章的答案 GPS Conversion - pixel coords to GPS coords ,但它没有按预期工作。我在图像和对应的坐标上取了一些点,并遵循与答案相同的逻辑,但将其反转以给我实际图像 X , Y职位。
上面帖子中给出的公式:

screenY0 //Screen origin (pixel corresponding to zero degrees latitude)
worldY0 //World origin (zero degrees latitude)
screenYscale //Screen scale (distance between 2 pixels)
worldYscale //World scale (distance between two latitude lines)
screenYpoint //Screen point (pixel y location)
worldYpoint //World point (latitude on the ground)   

screenY0 + screenYscale * screenYpoint = worldY0 + worldYscale * worldYpoint.
帖子说7.4 会有一些不准确的地方。米。提供的解决方案仅适用于靠近所选点的点或区域。当玩家移动一点时,该玩家的标记会跳出图像区域或离得很远。
编辑2:
我已经尝试了这篇文章中的解决方案 Convert GPS coordinates to coordinate plane用以下公式计算X位置:delta_long以度数表示田野角落的 GPS 差异。 delta_x是图像的宽度。horizontal_scale = delta_x/(cos(latitude)*delta_long)然后 x = ( lon - lon_origin ) * horizontal_scale我现在面临的问题是标记像这样在相反的 x 轴上移动,黑色箭头是实际玩家的移动方式,红色箭头显示玩家在应用程序内的移动方式。
enter image description here

最佳答案

首先,如果 GPS 坐标准确,您可以高精度地执行此操作。
其次,主要问题是旋转,如果 field 是直的,有 lat lng 线,这将很容易和直接(没有包子的意思)。
简单的方法是将坐标转换为类似于真实场的旋转图像,然后将每个 X、Y 点旋转到新的直线图像。 (见下图)
enter image description here
这是知道天使如何旋转 x,y 的方法:

double x,y;
double newX,newY;
double angle;

//Test values:
x=1;
y=1;
angle = 45;

double rad = angle*M_PI/180;

newX = x * cos(rad) - y * sin(rad);
newY = y * cos(rad) + x * sin(rad);
更新
long double lat1,lat2,lng1,lng2; //fill these with GPS coordinates
double x1,x2,y1,y2;//fill these of rectangle coordinate in the image

long double realWidth = distance(lat1, long1,lat2,long1);// distance btween the upper left corner & the upper right corner
long double realHieght = distance(lat1, long1,lat1,long2);// distance btween the upper left corner & the lower left corner

double image1Width = abs(x2-x1);
double image1Hieght = abs(y2-y1);

long double playerLat,playerLng;//fill the player lat lng GPS coordiantes 

POINT imagePlayerXY = convertGPS2xy(lat1,  lng1, playerLat,  playerLng, realWidth, realHieght, image1Width, image1Hieght);
//NOW rotate imagePlayerXY.x & imagePlayerXY.y to the final image
POINT convertGPS2xy(long double latOrigin, long double lngOrigin,long double playerLat, long double playerLng,long double realWidth,long double realHieght, double image1Width,double image1Hieght)
{
    double lngRatio2Width = distance(playerLat,playerLng, playerLat,lngOrigin ) / realWidth; //horizantal distance from the player place to rectangle origin (then compute the width ratio)
    double lngRatio2Hieght = distance(playerLat,playerLng, latOrigin,playerLng ) / realHieght; //virtical distance from the player place to rectangle origin (then compute the Hieght ratio)

    POINT imageXY;
    imageXY.x = image1Width * lngRatio2Width;
    imageXY.y = image1Hieght * lngRatio2Hieght;

    return imageXY;
}


long double distance(long double lat1, long double long1,
                     long double lat2, long double long2)
{
    // Convert the latitudes
    // and longitudes
    // from degree to radians.
    lat1 = toRadians(lat1);
    long1 = toRadians(long1);
    lat2 = toRadians(lat2);
    long2 = toRadians(long2);
     
    // Haversine Formula
    long double dlong = long2 - long1;
    long double dlat = lat2 - lat1;
 
    long double ans = pow(sin(dlat / 2), 2) +
                          cos(lat1) * cos(lat2) *
                          pow(sin(dlong / 2), 2);
 
    ans = 2 * asin(sqrt(ans));
 
    // Radius of Earth in
    // Kilometers, R = 6371
    // Use R = 3956 for miles
    long double R = 6371;
     
    // Calculate the result
    ans = ans * R;
 
    return ans;
}

关于android - 转换 GPS 坐标以匹配自定义 2d 户外布局图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/70603285/

相关文章:

java - Android Studio - 无法识别的 VM 选项 'MaxPermSize=256m'

java - 星期几的Android日历问题

flutter - 如何在 flutter 中的 firebase 推送通知中显示图像

dart - Flutter 中的镜像文本

android - 如何在 flutter 中处理后退时的切换页面逻辑

google-maps - 如何将Google Map与聚合物一起使用?

javascript - Vuejs 生命周期问题,仅在 Webpack 加载器刷新页面上的元素后才填充数据数组?谷歌地图标记不显示?

android - 具有多个输出的 Camera2

java - 根据另一个字符串的值确定一个字符串?

Android:模拟位置几秒钟后变回原始位置