12

For my application I want to calculate my car/bike speed using iphone. How can i do that? Ideally, it should run continuously in the background.

JuJoDi
  • 14,627
  • 23
  • 80
  • 126
Sukeshj
  • 1,503
  • 1
  • 19
  • 25
  • 1
    I may be missing something, but: take GPS reading. Some period of time later, take another GPS reading. Find distance between these two points, divide by the time difference between the two readings. That's your speed. Repeat. – Michael Petrotta Sep 29 '10 at 05:20

2 Answers2

15

CLLocation includes a speed property that will give you the current speed of the device. (Note the comment about the accuracy at that link.)

To get the user's current location, follow the steps in the Location Awareness Programming Guide, under "Getting the User's Current Location".

Finally, to enable location updates in the background, see Receiving Location Events in the Background in the iOS Application Programming Guide.

Kris Markel
  • 12,142
  • 3
  • 43
  • 40
  • The Location Awareness Programming Guide has sample code. Also, look at the "Related Sample Code" for the CLLocationManager class reference. http://developer.apple.com/library/ios/#documentation/CoreLocation/Reference/CLLocationManager_Class/CLLocationManager/CLLocationManager.html%23//apple_ref/doc/uid/TP40007125 – Kris Markel Sep 29 '10 at 06:08
  • Just be aware that speed will be reliable once in motion and you are getting regular location updates. Once you have stopped, then updates will only occur if you travel the required distance configured when location service updates were started. – Martyn Davis Aug 21 '15 at 00:28
0

the only way i can think of is thru GPS. the accelerometer is out. but im not sure if enough information is provided thru "GPS API".

AlvinfromDiaspar
  • 6,611
  • 13
  • 75
  • 140