calculate accumulated distance using GPS in android - java

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.

Related

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.

Show map markers five/ten miles from users current location

I've been looking around countless tutorials and stack overflow posts and found nothing on this subject. I'm trying to allow users to set a numerical value (i.e. 5, 10, 15) of miles and then only showing map markers which are within that distance of the users' current location.
So, I have the users location value and I have a database of markers each with their own lat/lng values. What I want to do is:
Get users' current location in Lat/Lng.
Get the required distance value (5, 10, 15 miles).
Get all the map marker location which are 5 miles away from the users' location.
Hide all other markers that aren't.
It's pretty standard functionality when using Google Maps as a user but I just can't find any documentation on it at all. Could any provide any helpful links or some sample code?
I've been looking into LatLngBounds and I believe I can use this in my solution. Am I looking down the right path?
I would first find the min latitude and longitude and the max latitude and longitude using a distance formula (see http://www.movable-type.co.uk/scripts/latlong.html ). Then use the answers from Android - How to get estimated drive time from one place to another? to find those which match in terms of driving distance (which will be less than or equal to the min/max).
By finding the min/max lat/long, you reduce the overall number of calculations you will need to do.

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).

how to find distance between two areas in android

hi all
i want to fin out distance between two places. if i go from one place to another place by street by street the distance is vary and suppose i walk within a street the latitude and longitude may not be changed. so these method may not help me. is there any other way for calculating distance for my requirement it whould be great to me. please help me.
Based on what you're attempting to do I would suggest figuring out if you can implement a pedometer (walking distance meter) using the accelerometer, combine that with the coarse location API and/or the fine location API and the compass you should be able to implement a pretty good location logger.
Other than that I'm not sure what you're trying to do.

Calculate real time distance traveled using google maps

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)

Categories

Resources