判断长/纬度是否在矩形内

发布于 2024-10-29 02:31:51 字数 316 浏览 3 评论 0原文

给定左上角的长/纬度和右下角的长/纬度,我如何找出给定的长/纬度是否落在矩形内?

理想情况下,我会查看类似

bool IsWithinArea(float topLeftLat,float topLeftLong,
   float bottomRightLat,float bottomRightLong,float testLat,float testLong)

Update

内容。一个问题是,从长/纬度创建的矩形可能来自旋转的地图,因此右下角并不总是大于左上角......

Given a top-left long/lat and a bottom-right long/lat how can i find out if a given long/lat falls within the rectangle ?

Ideally i would be looking at something like

bool IsWithinArea(float topLeftLat,float topLeftLong,
   float bottomRightLat,float bottomRightLong,float testLat,float testLong)

Update

The one problem is that the rectangle created from the long/lat may be from a rotated map, so bottom right will not always be greater than top left...

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

愛放△進行李 2024-11-05 02:31:51

我们可以让它比琐碎的检查更有趣:

return new Rect(topLeftLat, topLeftLong, bottomRightLat - topLeftLat, bottomRightLong - topLeftLong)
      .Contains(testLat, testLong);

PS: Rect.Contains(... )方法

We can make it more interesting than trivial checks:

return new Rect(topLeftLat, topLeftLong, bottomRightLat - topLeftLat, bottomRightLong - topLeftLong)
      .Contains(testLat, testLong);

P.S.: Rect.Contains(...) method

梦幻的心爱 2024-11-05 02:31:51

不确定我是否想简单

bool IsWithinArea(float topLeftLat, float topLeftLong, float bottomRightLat, float bottomRightLong, float testLat, float testLong)
{
    return (testLat >= topLeftLat && testLat <= bottomRightLat && testLong >= topLeftLong && testLong <= bottomRightLong);
}

Not sure if I'm thinking to simple

bool IsWithinArea(float topLeftLat, float topLeftLong, float bottomRightLat, float bottomRightLong, float testLat, float testLong)
{
    return (testLat >= topLeftLat && testLat <= bottomRightLat && testLong >= topLeftLong && testLong <= bottomRightLong);
}
夏至、离别 2024-11-05 02:31:51

假设 Lat 是 x 坐标,Long 是 y 坐标,并且还假设坐标系的原点位于左上角:

public bool IsWithinArea(float topLeftLat,float topLeftLong,
       float bottomRightLat,float bottomRightLong,float testLat,float testLong) {

          return (testLat >= topLeftLat && testLat <= bottomRightLat && testLong >= topLeftLong && testLong <= bottomRightLong);

    }

Assuming that Lat is the x coordinate und Long is the y coordinate and also assuming that the coordinate systems has its origin at the left top:

public bool IsWithinArea(float topLeftLat,float topLeftLong,
       float bottomRightLat,float bottomRightLong,float testLat,float testLong) {

          return (testLat >= topLeftLat && testLat <= bottomRightLat && testLong >= topLeftLong && testLong <= bottomRightLong);

    }
耳钉梦 2024-11-05 02:31:51

一种方法是将长/纬度对标准化为简单的 x/y 坐标。那么它应该是一个简单的练习来确定一个点是否落在矩形内。

长/纬度到 x/y 的转换可以在这里找到:将纬度/经度转换为X/Y 坐标

One approach would be to normalize your long/lat pairs to simple x/y coordinates. Then it should be a simple excersize to determine if a point falls within the rectangle.

long/lat to x/y conversion can be found here: Convert Lat/Longs to X/Y Co-ordinates

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文