views:

102

answers:

2

Hi,

I need in my Android Application the Distance and the Driving Time between Two cities.

Is there a possibility to calculate this things for example via Google Navigator or Google Maps? (the driving distance, not the air-line distance)

+1  A: 

Yes, it's possible, but you need to use the Google Maps Web API, since the Android SDK doesn't have any route calculation features (anymore, since v0.9).

You can find some sample for route calculation here (see my reply: http://stackoverflow.com/questions/3109158/how-to-draw-a-path-on-a-map-using-kml-file/3109723#3109723)

What you do is you create a Google maps request URL including all necessary parameters like geo points and mode (pedestrian, driving) and then fetch the response as KML (xml) data (you just add &output=kml to the Google URL), which holds all the information you need (time and distance). You need to parse the response (kml/xml) then, with i.e. a sax parser, as in my sample code.

Also see this post: http://stackoverflow.com/questions/2689542/how-to-get-google-maps-public-transit-directions-by-http-server-side-request/3089908#3089908

Mathias Lin
+1  A: 

Instead of using the web api directly as mentioned above you should use the Java wrappers as provided by http://code.google.com/p/gdata-java-client/ with more information about the maps api in detail here http://code.google.com/apis/maps/documentation/mapsdata/developers_guide_java.html

Keep in mind that this is NOT the android maps jar api but additional api stuff so you will need to include the jar in your apk build.

Manfred Moser