【问题标题】:how to check if bounding box contains my point如何检查边界框是否包含我的观点
【发布时间】:2023-03-08 10:09:02
【问题描述】:

我想知道我的点是否在使用坐标的边界框中:

检查点:

CLLocation -> 48.847172 2.386597

边界框:

maxLat minLat / maxLon minLon

"48.7998602295",
"48.8198640442",
"2.46138595581",
"2.48138619423"

如何检查?

【问题讨论】:

标签: ios objective-c mkmapview coordinates bounding-box


【解决方案1】:

CGRectContainsPoint

bool CGRectContainsPoint (
  CGRect rect,
  CGPoint point
);

为你工作?

您可以像这样将CLLocationCoordinate2D 转换为CGPoint

CGPoint p = (CGPoint) { loc.latitude, loc.longitude };

【讨论】:

  • 我会考虑编写一个包装函数,它接受 CLLocation 并在从输入创建 CGRect 和 CGPoint 后调用 CGRectContainsPoint。
  • 如何将 CLLocationCoordinate2D 转换为 CGRect ?
猜你喜欢
  • 1970-01-01
  • 2015-03-07
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-02-02
  • 2019-12-26
  • 1970-01-01
相关资源
最近更新 更多