some days ago I sweared to post my improved implementation of the buggy Android-included Driving-Directions.
Moving from the original DrivingDirections to my own implementation was done in just a couple of minutes. The output of the implementations are not directly the same but really similar and easily 'mappable'. Where my implementation is more reliable than the 'untransparent' Google-one which was really buggy.
This implementation is not a final one at all but is usable. Interfaces and method declarations may and probably will vary over time.
Exactly the same code you will find in the attached zip is what I use in my AndNav!-Application.
:warning: What you need is a GOOGLE APPID
For now I'll attach a complete sample-project. Description follows when I have more time

This is all you have to do:
Using java Syntax Highlighting
- /* This line is all you need =) */
- Route r = RouteFactory.create(Nationality.USA,
- "37.544694,-122.360356", // From: "San Francisco"
- "40.706384,-74.012672", // To: "New York - Broadway"
- "39.745684,-104.998457"); // Via: "Denver"
Parsed in 0.031 seconds, using GeSHi 1.0.8.4
As a complete project, producing the following output:
[align=center]
[/align]you need to code:
Using java Syntax Highlighting
- public class RouteSample extends Activity {
- TextView tv;
- /** Called when the activity is first created. */
- @Override
- public void onCreate(Bundle icicle) {
- super.onCreate(icicle);
- tv = new TextView(this);
- tv.setText("Please wait a moment...");
- setContentView(tv);
- new Thread(new Runnable(){
- @Override
- public void run() {
- try {
- /* This line is all you need =) */
- Route r = RouteFactory.create(Nationality.USA,
- "37.544694,-122.360356", // From: "San Francisco"
- "40.706384,-74.012672", // To: "New York - Broadway"
- "39.745684,-104.998457"); // Via: "Denver"
- /* Lets read out some values... */
- StringBuilder sb = new StringBuilder();
- sb.append("Total Distance (meters): ").append(r.getDistanceMeters()).append("\n");
- sb.append("Total Time (seconds): ").append(r.getDurationSeconds()).append("\n\n");
- sb.append("First subroute: Locationname: ");
- sb.append(r.getSubRoutes()[0].getEnd().getAdvancedAddress().getLocality()).append("\n");
- sb.append("Lenght of first subroute (meters): ").append(r.getSubRoutes()[0].getLengthMeters()).append("\n");
- sb.append("Overall Points in Polyline: ").append(r.getPolyLine().length);
- /* Show the values on the TextView. */
- setTextOnUIThread(tv, sb.toString());
- } catch (Exception e) {
- /* Oops something went wrong... */
- setTextOnUIThread(tv, "Error: " + e.getMessage());
- }
- }
- }).start();
- }
- /** Simple helper function. */
- private void setTextOnUIThread(final TextView t, final String s){
- runOnUIThread(new Runnable(){
- @Override
- public void run() {
- t.setText(s);
- }
- });
- }
- }
Parsed in 0.038 seconds, using GeSHi 1.0.8.4
Regards,
plusminus









