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.
Thanks in advance.
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.
Thanks in advance.
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
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.
the coordinate class has ready made function to get the distance, thus actually you can skip the math in there