andbook!.pdf - Learning Android Get an anddev.org - Android-Shirt Back to index
anddev.org Header Logo
FAQ Search Top rated articles Browse Feeds anddev.org - Authors Contact Details Register Log in

Route - Improved Google Driving Directions


 
       anddev.org - Android Development Community | Android Tutorials | Index -> Map Tutorials
Author Message
plusminus
Site Admin
Site Admin


Joined: 14 Nov 2007
Posts: 2439
Location: College Park, MD

PostPosted: Mon Apr 28, 2008 11:45 pm    Post subject: Route - Improved Google Driving Directions Reply with quote

Hey guys,

License wrote:

This source by Nicolas Gramlich is licensed under a Creative Commons Attribution-Noncommercial-Share Alike 2.0 Germany License .
Permissions beyond the scope of this license may be requested at plusminus {at} anddev {dot} org .

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 Exclamation Do a quick GoogleSearch on how to get one. Then enter it to the Constants.java - Interface.

For now I'll attach a complete sample-project. Description follows when I have more time Sad
This is all you have to do:
Java:
                         /* 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"


As a complete project, producing the following output:

you need to code:
Java:
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);
               }
     });
    }
}


License wrote:

This source by Nicolas Gramlich is licensed under a Creative Commons Attribution-Noncommercial-Share Alike 2.0 Germany License .
Permissions beyond the scope of this license may be requested at plusminus {at} anddev {dot} org .


Regards,
plusminus



RouteSample.zip
 Description:
Route-Sample ( 200kB )

Download
 Filename:  RouteSample.zip
 Filesize:  200.41 KB
 Downloaded:  192 Time(s)


_________________
Please remember, that this board is give & take Smile

| Android Development Community / Tutorials
Back to top
View user's profile Send private message Send e-mail Visit poster's website
brijeshthakur
Junior Developer
Junior Developer


Joined: 23 Jul 2008
Posts: 10
Location: Banglore,India

PostPosted: Thu Jul 24, 2008 10:08 am    Post subject: Operation Time-Out Error Reply with quote

Hi PlusMinus.

Your DrivingDirection application giving me "Operation time-out error".

The LogCat Shows the Below Information

INFO/Connecting...(611):
Connecting to.."http://maps.google.com/maps/nav?hl=US&gl=US&output=js&oe=utf8&q=from%3A37.788081%2C-122.415847+to%3A39.766325%2C+-104.989471+to%3A40.751418%2C-74.009399&key=ABQIAAAAQQcZviIzmIqVxEaMT12eqxT4XTUArVw0hfaJt-dPnDdoJ_2yihSOjsppgL4ku_kEd5DDd3kEV_K2AQ"


by the way. I got Google APPID from http://code.google.com/apis/maps/signup.html.

by giving "http://maps.google.com/map/nav" in the URL textbox.

Do Let me know where I am wrong.

Thanks in Advance.

Regards,
Brijesh.
Back to top
View user's profile Send private message
stunti
Once Poster
Once Poster


Joined: 08 Oct 2008
Posts: 1

PostPosted: Wed Oct 08, 2008 11:52 am    Post subject: Reply with quote

Hi,
Is there a way to get this library working again ?
MapPoint doesn't exists anymore.

Or is there another way to get driving direction?
Thanks a lot.
Back to top
View user's profile Send private message
Display posts from previous:   
       anddev.org - Android Development Community | Android Tutorials | Index -> Map Tutorials All times are GMT + 1 Hour
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


© 2007, Android Development Community
All rights reserved.
Powered by phpBB.