gpt4 book ai didi

android - 旋转后从地面叠加层获取 NW LatLng

转载 作者:搜寻专家 更新时间:2023-11-01 09:28:48 26 4
gpt4 key购买 nike

我需要从包围地面叠加层的矩形中获取 NW LatLng。使用 mOverlay.getBounds() 将使我在旋转之前得到我需要的点(getBounds 忽略旋转)。 enter image description here

这是地面叠加层,我需要的确切 LatLng 是红色点。当它完全位于北/南(左图)时,我可以使用 getBounds() 毫无问题地得到这个点。旋转图像后,我现在需要任何点,即包含我旋转的地面叠加层的北/南面矩形的 NW 角(右侧图像的红点)。

最佳答案

我不得不假设您正在使用“方位角”来旋转叠加图像并且图像的 anchor 是中心。此外,由于 map 是一个球体模型,当你说矩形时,我们实际上假设一个二维平面与图像中心的球体相切(未旋转)。

这个解释做了一个简化的假设,即旋转角度小于 pi/2 弧度,并且是顺时针方向。

这些都不是新的,所以没有功劳 - 但我尽力适应你的问题。

总而言之,此方法将 WGS-84 坐标系中的原始矩形(未旋转)转换为 x/y 坐标系(以原点为中心),计算旋转后的新 x/y,使用 trig 选择角,导出 x/y 超矩形的左上角并将结果转换回WGS-84球坐标系。

// convert your rotation value (bearing clockwise) to radians

// Using the bounding rectangle (which is of the non-rotated image) compute distance
// between nw and ne corner (width) and nw and sw corner (height) (in meters).
// The purpose of this is to establish an x/y coordinate system with origin being
// the center of the non-rotated image.

// Compute the corner coordinates of original bounding rectangle in an x/y coordinate
// system using the center as the origin (0,0) e.g. divide NW-NE width by 2 change sign as needed. Units are meters

// Compute rotated NW corner (x`,y`) (in x/y system) using original NW corner(x/y)
// and bearing:

// x` = x * cos(bearingInRadians) + y * sin(bearingInRadians) and y` = -(x * sin(bearingInRadians)) + y * cos(bearingInRadians)

// Compute the y-distance from original NW corner (x/y) to new NW corner (x`,y`)
// (subtract the y's)

// Compute latitude of super-bounding by using SphericalUtil.computeOffset using
// original NW lat-lng as 'from', and y-distance (meters) as distance and heading as 0 (north-up).

// Compute the rotated SW corner(x``,y``) (in x/y system) in the same manner
// as the NW corner above.

// Compute the x-distance from original SW corner (x/y) to new SW corner

// Compute longitude of super-bounding rectangle by using
// SphericalUtil.computeOffset using original NW lat-lng as 'from', and
// x-distance (meters) as distance and heading as 270.

克服简化意味着选择要使用的正确角点,并将其映射到纬度和经度。

我希望类似的东西已经实现,但希望这有助于解释需要什么。快乐狩猎。

下面是上面的实现:

    GroundOverlayOptions goo = new GroundOverlayOptions();
BitmapDescriptor bd = BitmapDescriptorFactory.fromResource(R.drawable.rectangle);
goo.image(bd);
goo.position(latLng, 1000F);
GroundOverlay go = mMap.addGroundOverlay(goo);
LatLngBounds llb = go.getBounds();
LatLng ne = llb.northeast;
LatLng sw = llb.southwest;

PolylineOptions po = new PolylineOptions().add(new LatLng(llb.northeast.latitude,llb.southwest.longitude))
.add(llb.northeast)
.add(new LatLng(llb.southwest.latitude,llb.northeast.longitude))
.add(llb.southwest)
.add(new LatLng(llb.northeast.latitude,llb.southwest.longitude));
Polyline polyline = mMap.addPolyline(po);

MarkerOptions mo = new MarkerOptions();
mo.position(new LatLng(ne.latitude,sw.longitude));
mMap.addMarker(mo);
goo.bearing(25.0F);
GroundOverlay go2 = mMap.addGroundOverlay(goo);

double rads = Math.toRadians(25.0);

float[] result = new float[1];
Location.distanceBetween(llb.northeast.latitude, llb.southwest.longitude, llb.northeast.latitude, llb.northeast.longitude, result);
float width = result[0];
Location.distanceBetween(llb.northeast.latitude, llb.northeast.longitude, llb.southwest.latitude, llb.northeast.longitude, result);
float height = result[0];

float upperLeftX = -(width / 2);
float upperLeftY = (height / 2);

float lowerLeftX = upperLeftX;
float lowerLeftY = -upperLeftY;

double newX = (upperLeftX * cos(rads) + upperLeftY * sin(rads));
double newY = (-(upperLeftX * sin(rads)) + upperLeftY * cos(rads));

double deltaY = abs(newY - upperLeftY);
LatLng newLat = SphericalUtil.computeOffset(llb.northeast, deltaY, 0.0);

double newX2 = (lowerLeftX * cos(rads) + lowerLeftY * sin(rads));
double newY2 = (lowerLeftX * Math.sin(rads) + lowerLeftY * cos(rads));

double deltaX = abs(newX2 - lowerLeftX);
LatLng newLng = SphericalUtil.computeOffset(llb.southwest, deltaX, 270.0);

MarkerOptions mo2 = new MarkerOptions();
mo2.position(new LatLng(newLat.latitude, newLng.longitude));
mMap.addMarker(mo2);

结果:

enter image description here

注释

  1. 使用线性缩放投影球体表面时会出现错误,但在处理小区域时会显着减少。

引用资料:

  1. 对于我引用的三角函数:rotate rectangle
  2. Android 资料 (1):Spherical Util

关于android - 旋转后从地面叠加层获取 NW LatLng,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48895334/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com