Objective C - iPhone 比较 2 个 CLLocations/GPS 坐标
好的,感谢 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
是的,您可以使用
getDistanceFrom
来获取两点之间的距离。距离以米为单位。您可以使用该比较与位置管理器的当前水平精度进行比较,以确定您是否大致处于“奖励一”位置。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.