Calculate real time distance traveled using google maps - java

There is a requirement to find the real time distance traveled using google maps. This should be calculated by the phone app itself. When I mean real time, I mean for example if the user is traveling to point A, the user can get to the point in many ways, what I want to do is calculate the total distance the user has traveled real time and not just assume and calculate the distance between the two points (which would not give the correct answer).
I googled around for this problem but could not find any method in doing so.
I personally thought of storing the longitude and latitude on the phone in a list and after the user reaches the destination the distance is caluclated using these points. However this means that I have to decide the interval in which these points are stored (every 1 min or so), which would mean that I would place location points in the list even though the user was actually still on the same road, which is quite unnecessary. Unless if anyone knows how to store the points at the appropriate time or some other solution
I am well more or less stumped on this problem, any help is really appreciated
The mobile platform is Android
Thanks,
MilindaD

I think the best solution is to save the position each X seconds, and then calculate the total distance iterating between them, and to get the time, you just need to see the diference between the last point and the first one.
This is how gps tracking apps work.
Hope this helps ;)

I did it once and it is fairly simple. Use a service with a LocationListener. On every onLocationChanged() save the current Location, At the end you can calculate with Location.distanceBetween() all distances between these saved Locations.
Please keep in mind that it becomes more accurate with faster tracking. For a walk you need less updates than driving a fast car. This can be set with minDistance and/or minTime in LocationManager.requestLocationUpdates().

you could try takeing the start point (IIRC their Long and Lat) then the end point and working out the euclidean distance between the two (see http://en.wikipedia.org/wiki/Euclidean_distance ).
I guess you what a better reloution then two point throgh, so take a third (or more) reading and work out A->B then add B->C.
Repeat for the resaloution you need.
to get the time of the journey. start a clock and stop it at the end (again you could take intermittent points if you wanted)

Related

Is it possible to determine the location of a phone in relation to another phone (or just get accurate GPS data) based on bluetooth or wifi?

I want to determine the location or the direction of a phone in relation to another phone using wifi or Bluetooth since GPS is not accurate enough indoors. Is this possible? I have tried googling it, but I have not been able to find a sufficient answer.
Thank you for your help!
No, you can't- you don't get enough data. Let's say you have 2 phones A and B. A can broadcast a message over bluetooth (this works the same for any other radio type, including wifi). The receiver B can determine it's strength when it receives it. From that and knowing how strong it was when sent, it can know its approximate distance. So you don't know what direction A is, but you know how far he is. And that's all you can get. So you know B is in a circlearound A (this isn't 100% accurate as due to signal noise you're actually in a 2d- ring, but lets assume a perfect world here).
Now imagine A is at a fixed point. Now lets add in phone C, at another fixed point. If you got a message from A and from C and did the same signal strength math, you now B's distance from A and C. Two circles, one around A and C. B will need to be at one of the crossing points- there will be 2 of them. You don't know which.
Now add in D. You now have 3 circles. All 3 will cross at only 1 point. That's B's location. It takes 3 fixed points to find someone. In museums and other indoor places that do location tracking, you'll see dozens of bluetooth beacons, each with their own id, and you triangulate based on which ones you can see at all and which are closest.
That's finding your location relative to fixed points. With non-fixed points, to find someone you'd need to become the 3 points yourself. Imagine B stands still. A can make a reading. Then he can move 10 feet away. Take another reading. Move 10 feet away (not all in one line). Now you have 3 readings and can figure out where B is using the same math as above. Please note that to use this, you have to know very accurately exactly how far and in what directions you moved between the 3 points. If you don't, you won't get any accuracy. It doesn't matter what direction you moved, but you need to know that and the distance exactly.
Now if B is moving, that math will be off. But given the short distances involved it would probably be close enough to find them.
(all this assumes elevation isn't invloved, if it is you need more points).
Now if you're willing to take a hardware based answer- if you have something on the phone that can block the bluetooth signal and you can adjust physically you could get directionality by blocking it to all but a 30 degree cone, trying to read the signal, and moving the blocker until you can. Then you know the direction to within 30 degrees and the distance. But my guess is you're not willing to have them carry lead phone cases :)

Vehicle Routing with Traffic Jam

I was building a prototype of vehicle routing application using google maps and optaplanner. I change the distance based scoring to duration based scoring, where the duration value was calculated using distance / avg speed of vehicle.
Now I want to add traffic jam variable into my application. The traffic jam variable was implemented as additional duration value from the current location to another location (I using a map of location and double just like distance variable in RoadLocation class). When I tried it to run it, the result was always same with the previous one. Here is the result from the first run :
I draw some red line to represent the traffic jam, and then try to re-run the solving phase. Here is the second result:
The result was the same with the previous one. My questions is, what the best method to apply the traffic jam variable into vehicle routing problem? Does anyone has any experience adding this variable? Any comment and suggestion will be appreciated.
Thanks and regards.
This paragraph is just an introduction. If you wanna skip it, do it. ;-)
I have implemented a similar approach with traffic jams, but it was not a real-time system. The solution runs every X minutes, which is absolutely fine.
That gave me the benefit for pre-calculating the ways and routes for the complete road network, before the actual optaPlanner calculation starts.
This saves time for the real calculation of optaPlanner.
The network consists of vertexes and arcs. For each arc you'll have a weight.
Here starts the real deal for you.
Let's assume that you implement a Dijkstra or A-Star algorithm for the precalculation step for all places and how to get there. These way finding algorithm is seleting the arc with the lowest "travelling" costs. For each arc/road, which would be blocked, we assume a distance of DOUBLE.MAX_VALUE. This value can be interpreted as "not driveable" or drastically said: This connection between two vertexes even doesn't exist for the current solution finding process. So the way finding algorithm will simply skip this road. For every driveable road, we calculate the real costs, e.g. distance or take an approximation out of experience.
The optaplanner process itself just uses the precalculated way finding mechanism, e.g. compares the calculated distances for getting from place A to place B.
For setting the distance variable to DOUBLE.MAX_VALUE you can decide between user based information, information of other providers like google or admin based rules. As my experience goes along with user based content vs. admin based actions, I can recommend both ways.
Let's discuss the user based action: The user can have the same set of GUI actions as the admin for flagging a way as "jammed". For the next optaPlanner iteration the flag is going to be involved. If you have GPS data of your users you can get the approximate velocity. For each intervall of the GPS measurement you can calculate that velocity. If the velocity is on a road (not a crossing), and below a defined minimum velocity (let's say 1mph or 2 kmh), then you can ask the user if it's a traffic jam or not via popup OR block that road automatically without asking the user. If you chose the popup dialog then a lot of different users have to vote "yes" within a defined time slot, e.g. half an hour, then the road get's blocked. You can resolve the traffic jam, when a lot of users drive the road again and send the GPS coordinates of that road.
The main advantage of the automatic approach is, that you'll have a system based approach with a low error rate.
If you take the manual approach via admin, then you have to take care of implementing a GUI for displaying the roads and enabling/disabling the blocked attribute for a road.

calculate accumulated distance using GPS in android

I am a new user and is new to android programming.
I am trying to creating a android application that calculate distance a user traveled using a GPS. one of the examples I can think is like a treadmill where it shows the accumulated distance. except the user will be moving around and using a gps to see how long he walked/run.
i can activate a gps, using LocationManager and LocationListener to get a longitude and latitude. but i do not know how to go from there
all my research shows how to calculate distance traveled between 2 points, A to B in a line,shortest distance. but i wanted to have a real-time accumulated distance no matter in which direction the user is going. or how fast.
i do not understand how the logic/math behind the calculation so it is hard for me to come up with a solution. the get.DistanceTo and DistanceBetween also calculate distance in a linear line right?
i also heard something about a accelerometer to use with a GPS. but based on my research so far(not too in depth) it also shows a single location, but i also do not know how to calculate distance from there. or how does it works with GPS
does i have to use longitude and latitude or others?
i'm quite weak in programming but this is a task i have to complete. Thanks
The Google Distance Matrix API
Can't take credit for the answer, I got it from Another post
I would stick to the GPS data and not worry with the accelerometer. Then you would have to record the position in defined intervals and just add the distance to the last point every time you check. The closer you want to get to the real distance the more frequently you have to check. You could then make the interval dynamic e.g. check less often if you go faster.

Android Algorithm for find all Geopoints within a given distance

In my naive beginning Android mind I thought the way to do this would be to loop through each of the objects checking if proximity falls within X range and if so, include the object. This is being done with Google Maps and GeoPoints.
That said, I know this is probably the slowest way possibly. I did a search for Android Proxmity algorithm's and did not get much really. What I am looking for is best options with regard to this the more efficiently.
Are there any libraries I have not been able to find?
If not, should I load these Location objects into SQL then go from there or keep them in a JSONArray?
Once I establish my best datastructure, what is he best method to find all Locations located with X miles of user?
I am not asking for cut and paste code, rather the best method to this efficiently. Then, I can stumble through the code :)
My first gut feeling is to group the Locations by regions but I'm not exactly sure how to do this.
I could potentially have tens of thousands of datapoints.
Any help in simply heading in the right direction is greatly appreciated.
As a side note, I reach this juncture after discovering that a remote API I had been using was.. well.. just PLAIN WRONG and ommiting datapoints from my proximity search. I also realized that if just placed on the datapoints on the phone, then I could allow the user to run the App without internet connection, and only GPS and this would be a HUGE plus. So, with all setbacks come opportunnities!
The answer depends on the representation of the GeoPoints: If these are not sorted you need to scan all of them (this is done in linear time, sorting wrt. distance or clustering will be more expensive). Use Location.distanceTo(Location) or Location.distanceBetween(float, float, float, float, float[]) to calculate the distances.
If the GeoPoints were sorted wrt. distance to your position this task can be done much more efficiently, but since the supplier does not know your position, I assume that this cannot be done.
If the GeoPoints are clustered, i.e. if you have a set of clusters with some center and a radius select each cluster where the distance from your position to the cluster's center is within the limit plus the radius. For these clusters you need to check each GeoPoint contained in the cluster (some of them are possibly farther away from your position than the limit allows). Alternatively you might accept the error and include all points of the cluster (if the radius is relatively small I would recommend this).

Finding the direction with GPS

Please consider this scenario:
An app knows which of a few routes the phone is on, thanks to GPS. That means it knows the only two directions that the device will be traveling in.
Am I right in thinking that the best way to determine which direction the phone is moving (it will almost certainly not be pointing the right way, so compass is not an option) is to poll the GPS until it starts moving, and find the direction the Co-Ords are moving in?
How regularly, and for how long, do you suggest the polling polls/lasts for?
Thanks in advance!
This is a science in itself, read up on kalman filtering. Basically, the difference between the last two points given by the GPS is the direction you are moving. Then errors come into the equation and you need to start learning about good ways to filter the data and get better results.
Attempt at explaining kalman filtering:
A kalman filter uses a Model to predict new values for the predicted thing. It makes an assumption like "stuff usually moves in the direction of their speed. so if it was here a second ago, it will be there now". It will then use this model to predict the next point and when it actually can measure the next point, it will use that data to update the model and assess the accuracy of the prediction. Then it will start giving you predictions based on a combination of real data and predictions which are weighted according to it's measurements of the prediction accuracy. So if the model is normally very accurate but there is suddenly a jump in the data, it will assume that it is a fluke and it will not let it affect the value too much. If the data is very jumpy, it will trust the data more and the model less.

Categories

Resources