-3

Using Google Map or any other map provider, if I have a GPS tracking device on a train, how do I get a railway distance between the train to the nearest train station?

Zarul Zakuan
  • 510
  • 3
  • 13
  • You need the track data and the location of the nearest train station. You might be able to get the location of the nearest train station from Google Maps, but the track data isn't available from the APIs. – geocodezip Dec 23 '18 at 16:12
  • 1
    Stackoverflow is not the correct place to ask a “How do I do...” type question. You should have tried something yourself first and show your code. https://stackoverflow.com/help/how-to-ask – Magnas Dec 23 '18 at 16:51
  • This is the wrong place to ask that type of question. – Magnas Dec 23 '18 at 18:13
  • Just a tip. There is also a GIS stack exchange which is more open to "how do I do" type questions like this: https://gis.stackexchange.com/ – rbrundritt Dec 30 '18 at 02:13

1 Answers1

1

If you are physically on the train and have a GPS tracked device, most mapping platforms won't be able to snap you to the railway line unless the device/user is sitting at a station. If the device is close enough to road, usually within 150 meters, it will likely snap to that. If the user was at a station, its much easier and just a matter of calculating a transit route.

That said, most transit data uses straight line distances between stations and not true travel distances. I've worked with many large transit agencies around the world and many of them don't even know where their railway lines run, let along the true distance between stations. What they do know is how long it takes to travel between stations and that's all they generally care about for the most part.

To do this correctly, you will need access to the raw railway line vector data. Open street maps has some, but I don't know how accurate or complete it is. Many agencies or governments publish this data, but often it is just straight lines drawn between stations, so you would have to look and see what's available. Once you have complete data, then you can snap to your GPS point to the nearest railway line then calculate the shortest path along all railway lines to the station in question. This is fairly complex, but I've done this before for both railway lines and private road networks. There are several open source libraries that can assist with this, like this one: https://github.com/perliedman/geojson-path-finder

rbrundritt
  • 16,570
  • 2
  • 21
  • 46