thunpisit
thunpisit

Reputation: 117

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

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.

Upvotes: 3

Views: 4170

Answers (1)

Azat
Azat

Reputation: 6795

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

Upvotes: 8

Related Questions