More accurate gps data?
I’m trying to make a small gps logger that tells me how far I ran in a given time, but it seems as if the gps data isn’t very consistent. This is a shortened version of my code:
import location, time, math def distanceFromCoords(long1, lat1, long2, lat2): #calculate distance between two coordinates #convert latitude and longitude to spherical coordinates in radians degrees_to_radians = math.pi/180.0 #phi = 90 - latitude phi1 = (90.0 - lat1)*degrees_to_radians phi2 = (90.0 - lat2)*degrees_to_radians # theta = longitude theta1 = long1*degrees_to_radians theta2 = long2*degrees_to_radians #calculate spherical distance from spherical coordinates. cos = (math.sin(phi1)*math.sin(phi2)*math.cos(theta1 - theta2) + math.cos(phi1)*math.cos(phi2)) arc = math.acos(cos) # multiply arc by the radius of the earth (3960 miles or 6371 kilometers) return round(arc*6371*1000) #multiplied with 1000 to get meters location.start_updates() #start location updates if True: distance = 0 #total distance travelled startTime = time.time() #set starting time of timer #to calculate distances two coordinates are needed. coord1 is the coordinate I was at, and coord2 is the coordinate I am at now coord2 = (location.get_location()['longitude'],location.get_location()['latitude']) while True: coord1 = coord2 #set coord1 to coord2 from previous loop repetition coord2 = (location.get_location()['longitude'],location.get_location()['latitude']) #get current coordinates distance += distanceFromCoords(coord1, coord1, coord2, coord2) #add distance between coord1 and coord2 to the total distance travelled print('\n', round(time.time()-startTime), '\n', distance, '\n') time.sleep(1) location.stop_updates() #I know, this never gets executed :D
If I don’t move my iPad and leave it for twenty seconds, the code tells me that I already moved about 50 meters! When doing a cooper run (you have 12 minutes time and need to run as far as possible) these 50 meters would already change my grade substantially (yeah, I’m still in school).
Is there any better way to do this? After all most apps (runtastic, google maps ...) manage too.
njm last edited by
@Drizzel, I think the issue is that after starting location updates, it takes some time for it to stabilize. I found that usually after 8 seconds the lat/long readings were no longer jumping around. I initially thought that it might be that your law of cosines equation was not well conditioned so I tried the haversine form and found little difference. Here is my mangle of your code:
To show what is going on, change the initial sleep interval to something small like 0.1sec and see just how much it bounces around.
Thanks a lot, I tried it out and it improved the data. Another interesting thing is that somehow the data seems to be more consistent when moving
saraparker last edited by saraparker
Landed here after generating my credit card CC Gen. Okay so, coming to gps there is an issue when the location is pointed out, It is not properly Allinged.
@saraparker Yeah, I figured that out too. But if you check some other GPS-logging app like runtastic, they have the same issue