How to get movement speed of iPhone

I was wondering how to keep track of movement speed of an iPhone (in mph if possible)



Getting GPS location should make it (take care of energy use).

Did you try it ?

This isn’t a question about a feature of the Swift language, so it’s posted in the wrong forum. Something like Getting Started might be better.

Depending on what you mean by “movement speed”, either the Core Location or Core Motion APIs would work.

Tested in simulator (Apple location):

     func locationManager(_ manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) {
          let newLocation = locations[locations.count - 1]
          print("Location", newLocation!)

I get:

Location <+37.33233141,-122.03121860> +/- 50.00m (speed -1.00 mps / course -1.00) @ 10/21/18, 4:10:11 PM Central European Summer Time

So, you get

- the speed in newLocation!.speed (in meters per second)

- the direction in newLocation.course :The direction in which the device is traveling, measured in degrees and relative to due north.)