×

Discussion Board

Results 1 to 4 of 4
  1. #1
    Registered User
    Join Date
    Jun 2008
    Posts
    8

    Question GPS: Keeping track of distance

    Is there any library or api function that can return a total distance stamp. Just like a timestamp but with the total distance instead so that i can take a 'distance stamp' at the start and then use this value to calculate the distance traveled since the application started.

    Example:
    Code:
    distance_since_start = current_distance - start_distance
    I want to make an application and part of the functionality is to keep track of the distance since the user pressed start. Is there any sample code for doing this or any good libraries?

  2. #2
    Regular Contributor
    Join Date
    Sep 2005
    Location
    Finland, Helsinki
    Posts
    323

    Re: GPS: Keeping track of distance

    Quote Originally Posted by pure_x01 View Post
    Is there any library or api function that can return a total distance stamp. Just like a timestamp but with the total distance instead so that i can take a 'distance stamp' at the start and then use this value to calculate the distance traveled since the application started.
    You probably have to calculate it by your self. Fortunately it is quite easy. Just positioning.position() and then calculate the distance between current and previous point e.g. by using Calculate.distance(lat1, lon1, lat2, lon2) function found from here:

    http://code.google.com/p/pys60gps/so...b/Calculate.py

    Example:

    Code:
    >>> import Calculate
    >>> Calculate.distance(60.2000,25.0000,60.2001,25.0000)
    11.111696663076945
    Add the result to the total_distance variable or something.

    NOTE: the result is accurate enough if the distance is less than a few thousand meters (I guess).

  3. #3
    Super Contributor
    Join Date
    Mar 2003
    Location
    Espoo, Finland
    Posts
    976

    Re: GPS: Keeping track of distance

    Quote Originally Posted by pure_x01 View Post
    Is there any library or api function that can return a total distance stamp. Just like a timestamp but with the total distance instead so that i can take a 'distance stamp' at the start and then use this value to calculate the distance traveled since the application started.
    Code:
    distance_since_start = current_distance - start_distance
    Sorry,

    One of the days, when I'm still in work mode: what do you mean with "distance travelled"? Would it be just like you say distance between starting point A and current position B - as a direct line? Or would you mean just like you say bit later the distance travelled when moving from A to B - including all the turns and wanderings meter by meter?

    Think carefully what you ask, because you might get it

    Btw calculating a direct line gets complicated when distance is long enough. You have to consider the fact that earth is a globe and distance is actually an arc... If it gets too complicated, you could check this site for possible help

    Cheers,

    --jouni

  4. #4
    Registered User
    Join Date
    Jun 2008
    Posts
    8

    Re: GPS: Keeping track of distance

    Quote Originally Posted by JOM View Post
    Sorry,

    One of the days, when I'm still in work mode: what do you mean with "distance travelled"? Would it be just like you say distance between starting point A and current position B - as a direct line? Or would you mean just like you say bit later the distance travelled when moving from A to B - including all the turns and wanderings meter by meter?

    ...
    What i am after is the total distance traveled since a certain point in time including turns and in the smallest possible unit (probably meters). The starting point for the counter could be from when the phone starts or when the program was started.

    Example:
    Code:
      
    if __name__ == "__main__":
        start_dist = gps.global_distance()
        last_dist = start_dist
        while True:
            time.sleep(1)
            glob_dist = gps.global_distance()
            current_dist = glob_dist - start_dist
            print 'you have traveled %d meters since the app started' \
                     % (current_dist)
    
            # calculate the speed, since the update is per second
            # the distance since the last update is the speed
            dist_since_update = glob_dist - last_dist
            last_dist = glob_dist
            print '%d meters per second' % (dist_since_update)
    Im not sure if the code above make sense since it is very early
    and i am on vacation and could not sleep, but it is the global_distance
    that is the interesting function. :-)

    The code above would work with any return value the first time the global_distance was called. So if the global distance counters starts counting on the first invocation or any point in time before the first invocation does not matter as long as the subsequent calls returns a value that is the same or has increased since the first call.

    It would be a nice to have method for apps that just tracks distance or calculates current speed.

    Thanx

    Regards
    Per

Similar Threads

  1. JSR-179API provider reset to stop GPS location activity
    By nicholso in forum Mobile Java General
    Replies: 15
    Last Post: 2009-02-06, 11:33
  2. Replies: 0
    Last Post: 2008-05-12, 09:57
  3. linking error
    By dakosurf in forum Symbian
    Replies: 1
    Last Post: 2008-03-27, 22:45
  4. linking error
    By dakosurf in forum Open C/C++
    Replies: 0
    Last Post: 2008-03-27, 09:20
  5. Bluetooth GPS simulator for j2me phone
    By vgps in forum Mobile Java Networking & Messaging & Security
    Replies: 2
    Last Post: 2007-02-09, 04:30

Posting Permissions

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