iOS: (Swift) How to show distance from current location and exist annotation on annotation subtitle

五迷三道 提交于 2019-12-06 08:44:42

问题


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

(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.

Thank You.


回答1:


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 is just double and distance calculated in meters



来源:https://stackoverflow.com/questions/29069970/ios-swift-how-to-show-distance-from-current-location-and-exist-annotation-on

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!