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?
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.
Related
How can we reduce Google Maps api calls??
in one of our app (similar like uber) we are using Google directions api to plot two points(source and destination) and dynamic path between them,
so we have to update this path every-time in 4-5 seconds ,
In 2 months mostly 1.2 million requests are getting generated for directions api , and google maps charging almost $5k-8k per month which is very high. Any mechanism to optimise the same.
Don't make the call every 4-5 seconds. Why are you doing that anyway? The location doesn't change that much in 4-5 seconds, it may not change at all (they may be stuck at a light). Instead, track their GPS location and update it only every few hundred meters. That's a good step one. A next step after that would be to look at the actual route data returned by the API, and use the GPS data to see if the user is following the route, and update only if the user significantly deviates from it. This is also how Maps and GPS devices work- you'll notice that deviating from a route takes some time for the device to notice, and then it recalculates.
To do the latter- the DirectionsResult object holds a set of legs. Each leg is the directions to a single waypoint (so if you're just going directly to one place, it will be a single leg). Inside that is a series of steps. Each step has start and end GPS coordinates. If you're moving in the general direction from start to end GPS coordinates, no need to recompute. Unless your route is extremely curved, this would be good enough. There's also paths within a step that provides a series of points along the step, you can probably use that if it exists to provide more exact navigation along complex steps.
I have a service, from which I get the user's location on an interval of time (e.g. 7 seconds). The walking path is displayed on the map, but as you can see there're many invalid locations, since the GPS receiver is trying to obtain the exact current position.
The blue one is the displayed walking path and the black one is the actual walked. I was thinking of using the IMU as kind of a filter in order to check whether the retrieved location is on the path, or the location provider needs more time to update it.
Is it possible doing it in this way?
Yes in theory its possible to improve the GPS position with an IMU, but it requires a Kalman-Filter, which is not trivial to set up correctly and get it working correctly on range of devices. There lots of resources on the internet explaining how a Kalman-Filter works and what it can be used for.
I also recommend reading this blog post: https://blog.maddevs.io/reduce-gps-data-error-on-android-with-kalman-filter-and-accelerometer-43594faed19c . The authors pretty much wanted to achieve the same thing as you by using a Kalman-Filter. They also published a library on github for a Kalman-based location estimation.
I want to build a prototype app that allows users to rope off a building such that when others open the app in that roped off area they can be located to that building without fail. Current geolocation services have many toss up scenarios that fail widely in many cases.
What could be a naive approach to overcoming this by potentially adding an additional service (like a simple wifi heat mapper) to clear up some of the location ambiguity in order to create a reliable bound over the location? Are their any APIs in existence to help with such a problem?
Are you talking about some specific buildings or any building that the user has entered? In the first case I would use beacons or IndoorAtlas. Both methods require you to visit the buildings and either install beacons or map it up with IndoorAtlas. With beacons it would be enough just to place one on each exit to keep track of who enters and exists the building.
There's really no possible way to reach building-level accuracy with a method that would be possible the extend to any building. The only exception would be some public buildings, which Google has mapped indoors (read more about the Google indoors project here). However, the list of available locations is still really limited.
Even though not optimal, the easiest way would be to use GPS/core-location for this project. According to our experiments, GPS never shows your location inside the building, where you are currently, but always about 15m outside of it. You could try placing a geofence that is slightly larger than the building itself outside of the locations you wish to use.
Whichever technology you end up using, you can try the Proximi.io API for a super simple solution of keeping track of the locations and geofences/beacons.
I am writing an Android-application that is supposed to download a bunch of addresses from my SQL-server, reverse geocode them, compare them all to my current location and return the one that is closest to me, not geometrically, but the one that I am the shortest driving distance from.
I have managed to get the reversed geocoding to work, but when I run my program a few times, I hit the OVER_QUERY_LIMIT on google. Needless to say, there are quite a few addresses in my database.
I understand that I could do this the quick and dirty way and just see which address is nearest to me by comparing the latitude and longitude of my current position and that of my addresses as opposed to comparing it to the actual driving distance. The problem with this is that this application will be used in a region where there are quite a lot of lakes to drive around and using that method will likely return quite a few stupid results.
How can I keep this from happening over and over? Can I present google with a view of all my addresses and just do a comparison once? I really need help with this one.
Actually, you will have to query a routing service (not necessarily Google Maps, to my knowledge also Cloudmade provides you with routing; there definitely are more) to get driving directions to each of the Points Of Interest around you and then select the closest one. This is a very bad practice, as you are very limited with the request amount.
According to the Google Maps API TOS (paragraph 10.1.3) you are not always allowed to do that.
What I did in a similar case was to store the coordinates for all POI, and look up the closest ones just by range of lat/lng.
i am developing an android application that use map view.
i can add point to the map, zoom, get current location and animate to point.
but how to get direction between 2 points?
when user click on point to show direction between current location and clicked location.
Thanks
but how to get direction between 2 points?
Math. This has nothing to do with Android. It has little to do with maps, even. It has everything to do with math.
Depending on the distances involved, you might be able to get away with treating things as plain Carteisan coordinates and do the necessary trigonometry. Over a significant distance, though, the curvature of the Earth starts to play a role, and the math will get harder.
You might consider using a search engine to find whatever versions of the formulas you would like to use.
in order to show a direction on maps (android)
you can try to make an Overlaying custom route on your application.
We shall further assume that the route returned may contain additional information such as the local slope of the route (which could be important if one is negotiating the route in a wheelchair, for example). Since this requires a network access that could block the main UI thread if there are network difficulties, we shall also use this example to introduce the important skill of putting time-consuming or potential UI-blocking tasks on a background thread. and use AsyncTask to run the process in the background. To use AsyncTask we must subclass it.
maybe this is helped you out.