# Thread: Speed calculation using HERE - Maps api ?

1. ## Speed calculation using HERE - Maps api ?

Hi,

I am using HERE- Maps api in my Windows Phone application.
Please suggest me a method to calculate speed.?

I have tried with assigning Accuracy to be high in geocoordinatewatcher. Then also I am getting speed as NaN.

2. ## Re: Speed calculation using HERE - Maps api ?

basically if it does not give you the speed with the data, then it is for some reason not available. Of course you could check the time between the positions and then use the functions provided in the corrdinate class to get the distance between them, and just calculate the speed from them

3. ## Re: Speed calculation using HERE - Maps api ?

I haven't yet tried it myself, but I believe that the following solution is quite reasonable.
Say you are constantly tracking the location of your device. Doing this allows you to receive new coordinates (let's say you receive new coordinates every second).
Thus, each second you should have two pairs of coordinates and should code your app so that the application would store them for a while:

x1, y1 (where X is latitude and Y is longitude) - is where you are now
x2, y2 (where X is latitude and Y is longitude) - is where you were exactly a second ago

Say L is the distance that you covered in that second. Then mathematically:

L = (arccos {sin(x1)·sin(x2) + cos(x1)·cos(x2)·cos(y1 - y2)})·R

where R = 6371km - (Earth average radius)

Given that the Earth isn't ideally round, using the average Earth radius will give you a slight error of 0.5% when calculating the distance that you covered.

Once you have the distance L in kilometers:

t=1/3600

where t is that single second we're using.

Then speed V would be:

V=L/t
V=L*3600

Ultimately, the formula is

V=(arccos {sin(x1)·sin(x2) + cos(x1)·cos(x2)·cos(y1 - y2)})·R·3600

Which will give you the result in the metric system (i.e. km/h).

NB:

1. I do believe that there's a much simpler way to do that. I'll keep you updated once I find anything.
2. I'm a lawyer and not a mathematician, so there might be some errors in my formulas, but I double checked it and it seems OK.

4. ## Re: Speed calculation using HERE - Maps api ?

the coordinate class has ready made function to get the distance, thus actually you can skip the math in there

5. ## Re: Speed calculation using HERE - Maps api ?

Originally Posted by symbianyucca
the coordinate class has ready made function to get the distance, thus actually you can skip the math in there
Lol) Great) I knew there had to be a shortcut, otherwise the math would take quite a while to hardcode)

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•