Objective C - iPhone 比较 2 个 CLLocations/GPS 坐标

发布于 2024-08-26 04:20:48 字数 521 浏览 9 评论 0原文

好的,感谢 Claus Broch,我在比较两个 GPS 位置方面取得了一些进展。我需要能够说“如果当前位置等于(列表中的任何 GPS 位置),那么做一些事情

我目前的代码是:

CLLocationCooperative2D BonusOne; BonusOne.纬度 = 37.331689; BonusOne.longitude = -122.030731;

这是模拟器在无限循环的 GPS 位置

CLLocation *loc1 = [[CLLocation alloc] initWithLatitude:bonusOne.latitude longitude:bonusOne.longitude];
double distance = [loc1 getDistanceFrom:newLocation];
if(distance <= 10000000) {

然后做一些事情 任何低于 10000000 的数字都

假定没有匹配项。

Ok , so thanks to Claus Broch I made some progress with comparing two GPS locations. I need to be able to say "IF currentlocation IS EQUAL TO (any GPS position from a list ) THEN do something

My code at the moment is :

CLLocationCoordinate2D bonusOne;
bonusOne.latitude = 37.331689;
bonusOne.longitude = -122.030731;

Which is the simulators GPS location at Infinite Loop

CLLocation *loc1 = [[CLLocation alloc] initWithLatitude:bonusOne.latitude longitude:bonusOne.longitude];
double distance = [loc1 getDistanceFrom:newLocation];
if(distance <= 10000000) {

Then do something
}

Any number under 10000000 and it assumes that there is no match.

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

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

发布评论

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

评论(1

箜明 2024-09-02 04:20:48

是的,您可以使用 getDistanceFrom 来获取两点之间的距离。距离以米为单位。您可以使用该比较与位置管理器的当前水平精度进行比较,以确定您是否大致处于“奖励一”位置。

CLLocation *bonusLocation = [[CLLocation alloc] initWithLatitude:bonusOne.latitude longitude:bonusOne.longitude];
float distance = [bonusLocation getDistanceFrom:newLocation];
float threshold = 2 * [newLocation horizontalAccuracy]; // Or whatever you like
if(distance <= threshold) {
  // You are at the bonus location.
}

Yes, you can use getDistanceFrom to get the distance between two points. The distance is in meters. You can use that comparison, compared with the current horizontal accuracy from the location manager, to determine if you are roughly at the "bonus one" position.

CLLocation *bonusLocation = [[CLLocation alloc] initWithLatitude:bonusOne.latitude longitude:bonusOne.longitude];
float distance = [bonusLocation getDistanceFrom:newLocation];
float threshold = 2 * [newLocation horizontalAccuracy]; // Or whatever you like
if(distance <= threshold) {
  // You are at the bonus location.
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文