GPS - Getting the distance,time while running and walking

后端 未结 5 1246
情话喂你
情话喂你 2020-12-19 18:51

i have a situation where i need to use GPS technique.

i need to find the distance between two points when the person is walking.

When the person starts walki

5条回答
  •  野趣味
    野趣味 (楼主)
    2020-12-19 19:26

    I suppose the question is one of walking..

    Are you walking on the streets, or as the crow flies?

    If it's streets, and your connected to the net, use google's api.. It calculates routing based on two points and returns XML.. Should be easy enough to figure out.

    If it's crow flies.. well then, just do (a*a) + (b*b) = (c*c) this is by far the easier.. You could have your user tap for major turns.. Or you could keep a runnable running every 10 seconds from when they hit start, and plot the points. Still a*a+b*b=c*c but just a bunch of steps.

    Of course you'd have to run it in a service.. And given the choice I'd go with that option. You could adjust the cycle time based on speed traveled. Faster would be smaller pauses. It requires less on your dataplan.


    EDIT
    Ah.. I see what you're looking for. Tis not what I thought you were asking for. Simplify.. convert lat/long to GPS. and then do simple math on the last point stored

    void addDistance()
    {
      newX = ...
      newY = ...
      deltaX = absolute(m_oldX - newX)
      deltaY = absolute(m_oldY = newY)
      m_distance += sqrt(deltaX^2 + deltaY^2);
      m_oldX = newX;
      m_oldY = newY;
    }
    void startOver()
    {
      newX = ...
      newY = ...
      m_distance = 0;
      m_oldX = newX;
      m_oldY = newY;
    
    }
    

提交回复
热议问题