views:

86

answers:

3

Hi,

I am woundering if it is possible to create a route on a map using a train track. I know its possible over normal roads.

Best regards, Paul peelen

A: 

It's available in the following regions: Google Transit

zwip
+1  A: 

It's certainly possible. (Broadly speaking, everything is possible) :-)

The first thing you'd need is data on the location of the railroad tracks. For the US, Canada and part of Europe this is publicly available as shapefiles, for example at: http://www.lib.unc.edu/reference/gis/datafinder/index.html?search_type=show_category_contents&datalayers=1&category_id=109

Once you obtained the shapefiles all options are open. You can convert the lines to google.maps.polyline() objects, (or GPolyline() if you're using V2 of the API), and load them on a map. It will all depend on what you want to achieve and what server side languages you're using. Getting rail directions is a completely different matter. :-)

Marcelo.

Marcelo
Thanks. Thats sounds about right to what I want to do. Do you have any examples or tutorials on how to convert those to polylines on the top of your head? That would be great!
Paul Peelen
Paul, converting them to polylines is not a one step process, and the way to work with those shapefiles depends on what you want to achive. How many lines do you expect to load symultaneously? If it is too many you should drop polylines, (which consume browser resources), and consider custom tiles instead. Will you need any DB functionality? Simple (MySQL) or advanced (PostgreSQL/PostGIS)? Are you using API V2, (Encoded polylines available), or V3 (no encoded polylines). Is the application for mobile devices? (again, resources considerations), etc. Now I'm out of comment space here ... :-)
Marcelo
Ok, I understand. I am using the build-in google-maps API for the iPhone. This is no web application as it seems you are referring to that. What I am trying to accomplish is to show the user which track the train will follow from station to station.I could shorten this down by only showing the track between the last and next station, but that would remove the "overall" picture of what route the train will take. This application is for Sweden only, but it can still be a large calculation. Any suggestions?
Paul Peelen
OK, what I would do is to grab the relevant shapefile(s) and import them into a PostgreSQL/PostGIS database. PostgreSQL has a utility to do the import. Then, when the user enters two stations you geocode them, (get their lat/lon from Google), and using your favorite server side language search the DB for the shortest route between them. Then read the individual lat/lon points that make up the route and output a JSON string to the client and create a polyline. For one route only polylines should perform fine, otherwise custom tiles. This is several different questions merged into one. :-)
Marcelo
Perfect. I'll try that. Thanks alot!
Paul Peelen
Paul, thanks for the bounty and good luck with your project! :-) Cheers, Marcelo.
Marcelo
A: 

iOS 4 introduces some new features like MKOverlay which can overlay circles, polygons onto a mapview. You might try this for drawing on the map.

Mugunth Kumar