简体   繁体   English

如何使用Swift找到我所在位置的距离

[英]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.

相关问题 如何在Swift 3中将我的应用程序的位置分享到WhatsApp - How can I share location from my app to WhatsApp in Swift 3 如何使用Swift 3获取当前的起始位置并在跑步后/跑步过程中测量距离 - How to I take my current starting location and measure the distance after/during a run, using Swift 3 如果我 select 我在 Swift 中的位置,我该如何比较? - How can I compare if I select my location in Swift? 如何在Swift的mkannotationview中设置位置? - how can I set up a location in my mkannotationview in Swift? 如何从苹果崩溃报告中找到 memory 位置? 从我的应用程序崩溃的地方。? - How can i find memory location from apple crash report? from where my app is crash.? 如何更新显示的 ETA 和距离值? Swift 4 MKDirections MapKit - How can I update my displayed ETA and Distance values? Swift 4 MKDirections MapKit 在iOS中找到我的位置和一个点之间的距离 - Find the distance between my location and a point in ios Swift:如何在几个小时内获取应用当前位置的时间? - Swift : How can I get time in hours of my current location for my app? 如何快速添加位置图标? - How can i add location icon in swift? Swift - 如何检测滑动手势距离放弃? - Swift - How can I detect swipe gesture distance to give up?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM