3

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.

thunpisit
  • 117
  • 1
  • 4
  • 12
  • Try doing the distance calculation and updating the subtitle in the didSelectAnnotationView delegate method (so the calculation is done on-demand with the latest user location). –  Mar 17 '15 at 12:09

1 Answers1

8

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

Azat
  • 6,745
  • 5
  • 31
  • 48