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: 2655
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:  952 Time(s)


_________________
Download my apps Idea
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: 12
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
gustavo
Junior Developer
Junior Developer


Joined: 02 Mar 2008
Posts: 12

PostPosted: Fri Nov 14, 2008 6:01 pm    Post subject: I canīt make it run Reply with quote

Can you tell me how can I get com.google.googlenav package? My 1.0_r1 sdk version can't find it.
Back to top
View user's profile Send private message Visit poster's website MSN Messenger
zak
Freshman
Freshman


Joined: 23 Sep 2008
Posts: 8

PostPosted: Fri Jan 09, 2009 5:30 pm    Post subject: Draw path on the map Reply with quote

hi plusminus! i have a question for you... i tried you code "RouteSample" but this don't allow me to draw the path on the map. it doesn't follow the routes but it just draws a straight line from "point A" to "point B" .
how can i solve it? is there another way?
thanks!



route.jpg
 Description:
 Filesize:  61.2 KB
 Viewed:  6224 Time(s)

route.jpg


Back to top
View user's profile Send private message
yorgosg
Developer
Developer


Joined: 30 Jan 2008
Posts: 32

PostPosted: Wed Jan 21, 2009 4:46 pm    Post subject: Re: Operation Time-Out Error Reply with quote

brijeshthakur wrote:
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.


can someone post the process of acquiring a google app id?

the above url you posted doesnt work (http://code.google.com/apis/maps/signup.html), I have managed to login with my gmail credentials to a google apps portal that has loads of info all over the place, all very confusing Sad

is there an easier way of getting an app id?

can anyone help?
Back to top
View user's profile Send private message
Tushaar
Freshman
Freshman


Joined: 27 Feb 2009
Posts: 2
Location: pune,India

PostPosted: Fri Feb 27, 2009 4:24 pm    Post subject: Reply with quote

hey hi +- .. i have gone thru ur posts .. and these are really helped me a lot .. wel thnx a lot ..
I want to do same stuff of driving directions but i am using SDK 1.0 .,. and googlenav API not supported in SDK 1.0
can u help me in this matter plz ..
thnx in advance Smile
Back to top
View user's profile Send private message Yahoo Messenger
linkmaster_6
Developer
Developer


Joined: 16 Oct 2008
Posts: 48

PostPosted: Mon Mar 09, 2009 11:02 pm    Post subject: Reply with quote

So is this made for sdk 1.0? or is that a no? is there no easy way to construct a path?
Back to top
View user's profile Send private message
ashish
Developer
Developer


Joined: 20 Feb 2009
Posts: 46

PostPosted: Thu Mar 12, 2009 10:07 am    Post subject: Reply with quote

hello plus/minus.your tutorial are excellent but problem is that now every one is using sdk1.0 so,many api's are not supported.so please in future,post the tutorial for sdk1.0 only.

In your driving direction tutorial you have used "import com.google.googlenav.DrivingDirection;" package which is not there in sdk1.0 so,do you know any other equivalent API..please let me know...

thanks in advance...............
Back to top
View user's profile Send private message
csie-tw
Freshman
Freshman


Joined: 21 Jun 2009
Posts: 2

PostPosted: Sun Jun 21, 2009 11:35 am    Post subject: Reply with quote

linkmaster_6 wrote:
So is this made for sdk 1.0? or is that a no? is there no easy way to construct a path?



DrivingDirection can not be used anymore since SDK 1.1.
However, I found a method to implement the Driving Direction function
without the package com.google.googlenav.DrivingDirection.


http://csie-tw.blogspot.com/2009/06/android-driving-direction-route-path.html


Back to top
View user's profile Send private message Visit poster's website
xenon
Freshman
Freshman


Joined: 11 Jun 2009
Posts: 2

PostPosted: Thu Jun 25, 2009 2:33 pm    Post subject: Reply with quote

csie-tw wrote:
linkmaster_6 wrote:
So is this made for sdk 1.0? or is that a no? is there no easy way to construct a path?



DrivingDirection can not be used anymore since SDK 1.1.
However, I found a method to implement the Driving Direction function
without the package com.google.googlenav.DrivingDirection.


http://csie-tw.blogspot.com/2009/06/android-driving-direction-route-path.html



Looks good, but is there any way to get the source of this?
It's kinda hard to read on the website and some lines are cut.
Back to top
View user's profile Send private message
zpk1234
Junior Developer
Junior Developer


Joined: 27 Jun 2009
Posts: 14

PostPosted: Sun Jun 28, 2009 7:36 am    Post subject: Reply with quote

csie-tw wrote:
linkmaster_6 wrote:
So is this made for sdk 1.0? or is that a no? is there no easy way to construct a path?



DrivingDirection can not be used anymore since SDK 1.1.
However, I found a method to implement the Driving Direction function
without the package com.google.googlenav.DrivingDirection.


http://csie-tw.blogspot.com/2009/06/android-driving-direction-route-path.html




but i cann't open the link
http://csie-tw.blogspot.com/2009/06/android-driving-direction-route-path.html
Back to top
View user's profile Send private message
arvind
Freshman
Freshman


Joined: 23 Jun 2009
Posts: 7
Location: Mumbai,India

PostPosted: Thu Jul 02, 2009 10:40 am    Post subject: Reply with quote

zpk1234 .... enable your browser / firewall to open sites of all languages.....


csie-tw ... your blog was very helpful thank you....
I have a Map with placemarks as bitmaps on it using overlay
Could anyone please tell me if there is any way i can handle the event of clicking a bitmap on the MapView...
Forgive me, my english little poor....
let know me if u understand my question....
Back to top
View user's profile Send private message
zpk1234
Junior Developer
Junior Developer


Joined: 27 Jun 2009
Posts: 14

PostPosted: Thu Jul 02, 2009 2:49 pm    Post subject: Reply with quote

arvind wrote:
zpk1234 .... enable your browser / firewall to open sites of all languages.....


csie-tw ... your blog was very helpful thank you....
I have a Map with placemarks as bitmaps on it using overlay
Could anyone please tell me if there is any way i can handle the event of clicking a bitmap on the MapView...
Forgive me, my english little poor....
let know me if u understand my question....


it is surprised that the mapview cann't receive the click message, and MapActivity is no response in onActivityResult when another Activity is stop too, i have no idea for this!
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.