How do I generate route based on distance in android - java

I am looking for a program that can produce routes based on distance criteria. For example, I give a start point and an endpoint that are the same and I want 5-10 different routes which start and end there but are about 5 miles long. Is there anything out there that can do that?
I know that Google Maps can do that with just a start and end but no distance parameter. I just want to have distance be a parameter and have the start and end points be the same.
Please check this link for reference: routeshuffle

Related

How to Show path from source and destination in Android app and Navigate the user within the App

I'm trying to develop an Android app and I'm able to fetch the destination lat and long from JSON response. I manged to collect the users current lat and long.
Now How can I show a route or Line from source and destination and update the users current location for every few seconds.
Is it possible to do this and show the ETA and distance between the markers?
Thank You
#Uday, the plotting of polyline and calculating the direction between two locations can be done using Google Maps Directions API.
The Google Maps Directions API is a service that calculates directions between locations using an HTTP request.
In this tutorial, you'll see how to use Google Direction API and Places API. It will also guide you on the implementation of API and Google HTTP Client Library for Java. For the ETA and distance between the markers Google Direction response has an object called Distance and Duration within "LEGS" array:
A DirectionsLeg defines a single leg of a journey from the origin to
the destination in the calculated route. For routes that contain no
waypoints, the route will consist of a single "leg," but for routes
that define one or more waypoints, the route will consist of one or
more legs, corresponding to the specific legs of the journey.
distance indicates the total distance covered by this leg, as a Distance object
duration indicates the total duration of this leg, as a Duration object
Here is a related SO question about travel time. It explains how to get the duration of each leg and distance until the end marker point and how to parse the distance and duration in your app.

Spring Data - MongoDb finding nearest locations around a route

I've a model contains geojson points. Finding nearest with spring data is quite easy but how can retrieve nearest location for a giving route?
I am getting the route information from google:
http://maps.googleapis.com/maps/api/directions/xml?origin=48.208174,16.373819&destination=48.340670,16.717540&sensor=false&units=metric&mode=driving
The route information from the maps googleapi is broken down into steps that have a start location and end location with latitude/longitude coordinates.
Computing the distance of the points in your model to all the start/end locations in the route would give you a measure of how far the point is from the route. The minimum 'distance' from the route start/end points would be the nearest location to the route.
You can optimize the computation by discard any points when the computed distance is greater than the previous minimum cumulative distance.
Google maps api returns 'steps' of the route, which has coordinates of the edges of that stretch.
You can use those edges to create extrapolated points on that straight stretch. Lets call them p1,p2,p3,p4...pN.
Then you run $near query in your database for these points, you will
get nearest locations around that route.
Open street map database gives information of coordinates of the route,
which you can use to supplement your data.
Detailed answer here : Get exact geo coordinates along an entire route, Google Maps or OpenStreetMap
First, you need to get this result and then put it in some array that contains Lat+Lng.
Second, create a method in your repository that contains the parameter you want search by with the term "Within".
Example:
List<MyObject> findByLocationWithin(Box box);
This method represent the respective condition:
{"location" : {"$geoWithin" : {"$box" : [ [x1, y1], [x2, y2]}}}
If you need more information you access the follow link:
http://docs.spring.io/spring-data/mongodb/docs/current/reference/html/#mongodb.repositories.queries
https://docs.mongodb.org/manual/reference/operator/query/box/

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.

how to match two routes from Google Directions API response?

I building an application that matches the route of a user with the routes of all others users. Routes of all users are collected using google directions api. i am not able to figure out a efficient solution to match the routes.
example: User 1 travels from A to B. User2 from L to M and User 3 from X to Y. Now, i have the direction responses from google map api(preferably json objects) which has latlng info of all the points in the three routes. Now i need to find if route A to B matches with other two routes either full or partially.[ By full,i mean that they have either same origin or destination and by partial, i mean if any two routes have some part common or atmost 2 kilometers part].
I can do this by comparing each point in route A to B with points in other routes.But this is a tedious task consuming all my resources and timetaking.
please help me with efficient solution.
I would be glad if there is any algorithm to simplify this task?
I can do this by comparing each point in route A to B with points in other routes.
This is just about the only way.
The only refinement is to Simplify the lines first. This reduces the amount of points you have to compare.
Do beware of the Google Maps API terms, you can't take the data you obtain from the API outside of a Google Maps application. So you should be fine as long as you keep the data within a Maps API website, but dont export the data anywhere.

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