[英]How can I find some distance from my location with Swift
I have an app that takes some results(lat,long) from my server and put annotations in my map depends the lat and long that it took. 我有一个应用程序,它从服务器获取一些结果(纬度,经度),然后在地图中添加注释,这取决于它花费的经度和纬度。
Now i put a slider that filters the results by kilometers (1-10) 现在我放了一个滑块,可以按公里数(1-10)过滤结果
How can i filter my query to add the annotation if the lat an long is in its radius location. 如果经纬度在半径范围内,如何过滤查询以添加注释。
Step 1 第1步
Initially convert your lat and long to CLLocation. 最初将您的经纬度转换为CLLocation。
Step 2 第2步
var one, two: CLLocation
// assign one and two
let distance = two.distanceFromLocation(one)
CLLocationDistance
is just double
and distance calculated in meters CLLocationDistance
只是double
,距离以米为单位计算
Step 3 第三步
convert distance to meters 转换距离为米
let distanceKM = distance / 1000
step 4 第四步
finally compare to distance with in range 最终与范围内的距离进行比较
if distanceKM > 1000 && distanceKM < 10000
{
// drop your pins
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.