Google Distance Matrix API - Train Distance

I am using the Google Distance Matrix API with Java. I want to calculate the distance between two cities. There is no train station in one of the cities. The problem is that google doesn't just calculate the distance on the train. It always adds car-distance from a city without a train station to the next city with a train station. But for my project, I just need the train distance.

This is 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 cannot find a solution to this problem.

+3


source to share


1 answer


Google Maps search algorithms were developed to solve real-world transport routes, which means that sending a train to a place where a passenger cannot get off is not possible and therefore not reflected in routes. I can't think of any way to extract this information from Google Maps, other than perhaps a direct request for Directions, although I doubt it will have different results since it uses (as far as I can tell) fundamentally the same algorithm for everyone his services.

Using a database like OpenStreetMap (using free, limitless APIs like Overpass for HTTP access in Java) is probably the best solution.If you want to fix things quickly and you can identify cities without train stations, then the linear distance between two cities will probably return a reasonable (albeit deflated) estimate using the Geometry Library .



Sorry I don't see a solution, but this is the best I have.

0


source







All Articles