I'm using the Google Distance Matrix API with Java. I want to calculate the train-distance between two cities. One of the cities has no train station. The problem is, google doesn't just calculate the train-distance. It always adds the car-distance from the city without trainstation to the next city with a train station. But for my project i just need the train-distance.
This is a part of my code:
DistanceMatrix matrix = DistanceMatrixApi.newRequest(context)
.origins(origins)
.destinations(destinations)
.mode(TravelMode.TRANSIT)
.transitModes(TransitMode.TRAIN)
.units(Unit.METRIC)
.await();
In the documentation I can't find a solution for this problem.
The Google Maps search algorithms were designed to solve real-world transportation routes, which means that sending a train to a location where the passenger cannot get off is not feasible and therefore not reflected in the routes. I cannot think of any way to extract that information from Google Maps, except possibly doing a direct Directions query, though I doubt it would have different results, since it uses (as far as I can tell) the fundamentally same algorithm for all of its services.
Using a database such as OpenStreetMap (using free, limitless APIs like Overpass to access via HTTP in Java) is probably the best solution. If you want a quick fix, and you are capable of identifying cities without train stations, taking the linear distance between the two cities probably returns a reasonable (though deflated) estimate using the Geometry Library.
Sorry there is not a solution I can see, but this is the best I have.
Related
I use OSMdroid and I want to get the count of lanes of the street i'm driving on.
Normal street have one lane in each direction. Highway have two lanes in each direction. Some streets have more. Is this information stored in OSM and how can I get this informations about my street?
I'm using an LocationListener to get the users position.
Have look at OverpassAPI, it allows to dig deep and fast in the OpenStreetMap objects around a specific position.
To perform OverpassAPI requests in your Android context, you can either try OSMBonusPack OverpassAPIProvider with the KML flavour, or implement your own request/response parsing.
EDIT
You will need a clear understanding of OSM lanes tagging conventions.
This said, I quickly made some trials using OverpassAPI interface integrated in OSMNavigator, just searching with "highway" key: it works.
When on an actual highway, I found "lanes=2" on each side. On usual roads, no "lanes" key defined.
I currently building an application that similar to Optaplanner Vehicle Routing Examples. The difference is: it is web based and the visualization & distance calculation will be using GWT Google Maps V3 direction service. Just like the optaplanner blog post at here: Visualizing Vehicle Routing with Leaflet and Google Maps
I actually a little bit confused about calculating the distance between each location, should I do it realtime? What I mean realtime is first load the locations (about 350 locations) and then calculate the distance between each location (which will result in 350 x 350 = 122500 direction request) before start the solving phase.
The other way that I could think about is, do the calculation of each locations distance and store it in database, then load the data before start the solving phase. But if I choose this way, how to handle the locations change? i.e. a new location added or an existing location deleted?
Also I have read about google maps API limitation, it state that the services only available for 2500 request per 24 hour. How to solve this limitation?
Any comments and answers will be appreciated. Thanks and regards.
I have successfully used MapPoint together with MPMileage and CDXZipStream to maintain a database of locations (address + coordinates) using MapPoint and CDXZipStream. Drive times between two points were maintained using MPMileage and MapPoint. MapPoint is no longer being sold by Microsoft, but you may be able to find a copy on eBay or find an alternative. MPMileage and CDX just made my job easier. I was able to interrogate MapPoint as much as I wanted - it provided travel time for about 8 trips per second - no limit but your time. My database now holds over 600,000 trips and 15,000 locations. Also, these products require expenditure of some $. I spent about $300 for the three products I mentioned, a lot less than a Google commercial license. Maptitude can be a replacement for MapPoint, but you may not be able to control street speeds as well with Maptitude.
Prior to running a solution, I had a query make certain that the required coordinates were geocoded and that the potential legs (travel between two points) were in the database. If not, I'd fill in or update the values using the tools I mentioned. My particular method is not conducive to on demand work, but you can probably program such a process yourself.
I limited search space by imposing some reasonable assumptions, e.g. no trips over 13 miles in my case. You may be able to impose similar constraints to limit your search space. At any one time, I probably only use about 60,000 of the travel times as only the needed times are loaded - and the rest remain in the database in case I need them in the future. Within the OptaPlanner solution, these are facts, not entities or variables. These facts provide the travel time between the two points.
Hope this helps.
I want to solve a Travelling Salesman Problem like Google Maps does in its DirectionsRequest with request.setOptimizeWaypoints(true);. It orders some Waypoints in a route so that the travelling-costs are minimal.
My question: Does anybody know which algorithm stands behind it? Any heuristic? Could not find any information by google, so far.
I informed myself and found a lot of insertion-heuristics, nearest neighbour, and so on... Or is it an exact solution procedure?
The Wikipedia page on the Travelling Salesman Problem references a number of algorithms for finding solutions. (But unless N is small, avoid the "exact" algorithms!)
According to this post from a Google employee, the source code for the Googles route calculation algorithms is available here:
http://code.google.com/p/or-tools/source/browse/trunk/examples/cpp/tsp.cc
http://code.google.com/p/or-tools/source/browse/trunk/src/constraint_solver/routing.h
... but it is not entirely clear if this is the "production" code for Google Maps.
From a comment in the source code:
// Solving the vehicle routing problems is mainly done using approximate methods
// (namely local search,
// cf. http://en.wikipedia.org/wiki/Local_search_(optimization)), potentially
// combined with exact techniques based on dynamic programming and exhaustive
// tree search.
This general issue (Google Maps vs TSP) is also discussed in various other SO questions.
References:
Optimal map routing with Google Maps
Travelling Salesman with Google Maps API or any other
What is a practical solution to the Travelling Salesman prblem, using Google Maps?
I actually am trying to find the distance between two places, I am new to this. I came to know about openstreetmap. But I am not sure what to do.
I found a traveling salesman application that uses osm to route.
But here my question is how to get a osm between places .e.g. "http://www.openstreetmap.org/api/0.6/map?bbox=10,30,10,30" this gives me the map of the box (10,30,10,30) .. but if I want to get the map between leeds and sheffield what should be my query.
Or is there any other way to find the distance.(As I am a student I want some open source way for my academic project..)
please suggest..
You should consider implementing this by yourself.
First, I suggest you to use the Overpass API to do your queries.
Then implement this algorithm over the ways you get from the Overpass API :)
For calculating the routing distance between two places you can use one of the various online or offline routers. There is also a list of various information for routing developers containing a list of libraries and other information.
If you have to obtain the location of a specific address before doing the actual routing you can use Nominatim.
I am building an sms based application that will retrieve railway schedules.Now the problem that I am facing is that if the user types the wrong name of a particular station(Suppose he writes 'Kolkta' instead of 'Kolkata') then my app would not be able to forward the result of query that has got nearest match to it.How will I do it?Is there an API in java for this?
I guess Apache Lucene provides support you want in java.
Lucence Apache sounds promising, but if you want something more straightforward that you can cook at home very easily, you can try computing the minimal edit distance between the user input and the entire set of railway names. This is a measurement of similarity between strings and can be computed very efficiently (especially in your case, where the strings are very short).
The link above contains a scary mathematical formula but this is the nature of all formal representations. They are scary. Scroll a bit downwards a you will find the extremely short pseudo code for the algorithm (almost copy paste).