Search code examples
androidgeolocationlocation

How To Generate A Path As User Changes Location


I'm developing an application which requires the user's path taken to be recorded, and measured. I'm already familiar with utilizing onLocationChanged to receive location change updates, but how could I use these Location points to create a complete path, encompassing their entire trip from one location to another?

I was thinking I could utilize each Location passed as a point, and simply connect all of the points with a polyline, but this seems to me like it would be a weird and slightly ugly line (as location approximations aren't always super-accurate).

Another idea I had would be to acquire each street the user travels down, and then ultimately connect them all, but I'm not even certain as to how I would perform this.

Any ideas?


Solution

  • The best method would be to have some kind of representation of the map, then keeping your recent locations in a data structure (omitting too close locations by keeping only locations in fixed deltas, for example). Then you could match the points to nearest roads, and calculate their projection on them to created a matched path on the map.

    Since I've implemented this before, I can tell that it involves quite a bit of work, having some representation of the map as a graph (say using OSM), and knowledge with geometric queries (in PL/PGSQL probably if we talk about OSM). The trigonometric calculation themselves are rather easy and can be found on the web (E.g. projection of point on a given line). To get quality results, you'll also have to deal with your progress along the route (I.e. filtering gps points that lead you "backwards" instead of "forward" by mistake due to GPS signal error).

    You'd better off starting with a working POC: Depending on your map implementation (Google / OSM)- Choose some kind of an online routing provider (http://wiki.openstreetmap.org/wiki/Routing/online_routers). Then you could send small navigation requests between locations you stored earlier. Since their delta is small, you'll probably get the relevant matched path on the road.

    Downsides: You depend on an external service and its quota, and can't serve many clients without paying.

    Advantages: You could build a working POC in a small amount of time (~hours)

    Either way, you'll be bound to the quality of your given map (e.g. updated roads, turn restrictions) that will determine the correctness of your results.