iOS:(Swift)如何在注释副标题上显示与当前位置的距离和存在注释 [英] iOS: (Swift) How to show distance from current location and exist annotation on annotation subtitle

查看:29
本文介绍了iOS:(Swift)如何在注释副标题上显示与当前位置的距离和存在注释的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在使用 Swift 语言开发基于 iOS 的地图应用程序.我想要一个建议,因为在我在地图视图上绘制所有图钉之后

I am currently working on map application base on iOS using Swift language. I would like an suggestion because after I plot all the pins on map view

(我使用 JSON 框架调用 Alamofire 从我的服务器接收数据)

(which I receive data from my server using JSON frameworks call Alamofire)

我希望地图上所有注释的副标题显示与用户当前位置的距离.

I would like the subtitle of all annotations on map to show distance from user current location.

现在它可以在地图视图上添加注释,但只能根据从我的服务器接收到的信息显示标题和副标题.

Now it can add annotations onto map view but can only show title and subtitle base on information receive from my server.

谢谢.

推荐答案

如果你有两个 CLLocation 实例,你可以用下面的代码计算距离:

If you have two CLLocation instances, you can calculate distance with the following code:

var one, two: CLLocation
// assign one and two
let distance = two.distanceFromLocation(one)

CLLocationDistance 只是 double 和以米为单位计算的距离

CLLocationDistance is just double and distance calculated in meters

这篇关于iOS:(Swift)如何在注释副标题上显示与当前位置的距离和存在注释的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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