如何判断用户是否在特定位置? [英] How To Tell If User Is At A Specific Location?

查看:88
本文介绍了如何判断用户是否在特定位置?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

基本上,我需要做的是找出用户是否在特定位置(例如场地上的IE)。如果用户是用户,则允许访问特定的ViewController。

Essentially what I need to do is find out if a user is at a specific place (IE at a venue). And if the user is, allow access to a specific ViewController.

我一直在网上寻找这个问题的答案,但令人惊讶的是,我一直没有找到任何东西。我会说我是iOS开发的新手。

I've been looking high and low for an answer to this problem online and surprisingly I haven't found anything. I will say I'm pretty new to iOS development.

我不需要像Ray Wenderlich教程中那样复杂的地理围栏,也不需要在后台运行它。我也不需要知道他们是进入还是离开。只是当用户单击按钮时它们是否在该区域内。

I don't need anything as complex as geofencing like in the Ray Wenderlich tutorial, and I don't need to run it in the background. I also don't need to know if they entered or left. Just whether or not they are within that area or not when the user clicks a button.

我已经可以使用CoreLocation获取用户位置,但是我对于如何确定用户是否在特定位置感到困惑。理想情况下,我希望半径约为5英里(这是一个很大的位置)。

I've gotten as far as being able to get the users location using CoreLocation, but I'm confused as to how I will go about identifying if the user is at the specific location. Ideally, I will want a radius of about 5 miles (It's a big location).

推荐答案

以及场地的位置,您可以执行以下操作:

if you have the user's location as well as the venue's location you can do the following:

let radius: Double = 5 // miles

let userLocation = CLLocation(latitude: 51.499336, longitude: -0.187390)
let venueLocation = CLLocation(latitude: 51.500909, longitude: -0.177366)

let distanceInMeters = userLocation.distanceFromLocation(venueLocation)
let distanceInMiles = distanceInMeters * 0.00062137

if distanceInMiles < radius {
    // user is near the venue
}

这篇关于如何判断用户是否在特定位置?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆