1

I am building an Android app where I want to display the actual railway line between two cities.

If I just draw a Polyline using the lat/long of intermediate stations, it produces straight lines between stations, which is not the real railway path.

Google Maps itself shows the railway lines, but the Maps SDK does not give access to that data.

How can I display realistic railway tracks between cities in my Android app (similar to what Google Maps shows)? Shown in this image from Google Maps enter image description here

1
  • 1
    Hello, the Maps SDK for Android currently doesn't have the fundamental railway track data that Google Maps renders on transit layers but you can upvote this issue issuetracker.google.com/429060508 and provide a business use-case or justification for additional information. Commented Sep 19 at 9:37

2 Answers 2

0

In regards to your statement:

"Google Maps itself shows the railway lines, but the Maps SDK does not give access to that data."

Assuming you are requesting directions to obtain the route or path for the railways. As per the FAQs in the Google Maps API documentation, since the map you provided appears to be in India and you are attempting to display railway tracks or directions, I believe the issue you are encountering is due to the Indian Railway Catering and Tourism Corporation not being supported for transit directions.

There is a specific question in the documentation that asks: “In which countries are transit directions available?” The answer is:

"The Routes API supports all Google Transit partners, except the Indian Railway Catering and Tourism Corporation and those in Japan."

Sign up to request clarification or add additional context in comments.

5 Comments

I am not asking for the Route API. I am asking how I can show railroads like the above picture. I have all the route info. The only option we currently have is to draw polylines. I just want to draw a railroad between two cities.
Actually, drawing polylines might be the best option out there, and as per your statement: "If I just draw a Polyline using the lat/long of intermediate stations, it produces straight lines between stations, which is not the real railway path." This is actually what you'll be expecting if the latlng you used are only pointing to the stations. It's like trying drawing a circle using four points that will result into a rectangle.
To accurately render the curves and turns of a railway line, you need a series of LatLng points that are very close together, and manually collecting these points would be incredibly difficult. Fortunately, there's an answer to that by using the overview_polyline from the Routes API (Directions API) Web Service by sending a HTTP request and decoding it to obtain the series of latlngs. However, as I mentioned regarding the FAQ, this might not be possible.
I found an alternative and it could be done by using GeoJSON (developers.google.com/maps/documentation/android-sdk/utility/…) instead. Although, in this case, you might use an open-source of geographic data like OpenStreetMap (OSM), or you may apply OpenRailWayMap (wiki.openstreetmap.org/wiki/OpenRailwayMap/API). Alternatively, you may try checking out using the shapes.txt (gtfs.org/documentation/schedule/reference/…) from GTFS and extract the latlng lists in which you can use to draw the
You may want to check this blog too daveinside.com/blog/…
0

Easyest way is to use Style Reference for Maps SDK for Android and set style for "transit.line" fill and stroke keys.

This is possible by creating JSON file src\main\res\raw\railways_map_style.json like this:

[
  {
    "featureType": "transit.line",
    "elementType": "geometry.fill",
    "stylers": [
      {
        "color": "#000000"
      },
      {
        "visibility": "on"
      },
      {
        "weight": 7
      }
    ]
  },
  {
    "featureType": "transit.line",
    "elementType": "geometry.stroke",
    "stylers": [
      {
        "color": "#000000"
      },
      {
        "visibility": "on"
      },
      {
        "weight": 3
      }
    ]
  }
]

add map style to your GoogleMap this way:

mMap.setMapStyle(MapStyleOptions.loadRawResourceStyle(getContext(), R.raw.empty_map_style));

Also, you can use online map style wizard tool for JSON preparation and map visualization. It should be something like that:

Railways

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.