Route - Improved Google Driving Directions

Tutorials that use the MapActivity. Many using GPS functionality.

Route - Improved Google Driving Directions

Postby plusminus » Mon Apr 28, 2008 11:45 pm

Hey guys,

License wrote:Image
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 :!: 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 :(
This is all you have to do:
Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1.                                         /* This line is all you need =) */
  2.                                         Route r = RouteFactory.create(Nationality.USA,
  3.                                                                 "37.544694,-122.360356", // From: "San Francisco"
  4.                                                                 "40.706384,-74.012672", // To: "New York - Broadway"
  5.                                                                 "39.745684,-104.998457"); // Via: "Denver"
Parsed in 0.030 seconds, using GeSHi 1.0.8.4


As a complete project, producing the following output:
[align=center]Image[/align]
you need to code:
Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. public class RouteSample extends Activity {
  2.        
  3.         TextView tv;
  4.        
  5.     /** Called when the activity is first created. */
  6.     @Override
  7.     public void onCreate(Bundle icicle) {
  8.         super.onCreate(icicle);
  9.         tv = new TextView(this);
  10.         tv.setText("Please wait a moment...");
  11.         setContentView(tv);
  12.        
  13.         new Thread(new Runnable(){
  14.                         @Override
  15.                         public void run() {
  16.                                 try {
  17.                                         /* This line is all you need =) */
  18.                                         Route r = RouteFactory.create(Nationality.USA,
  19.                                                                 "37.544694,-122.360356", // From: "San Francisco"
  20.                                                                 "40.706384,-74.012672", // To: "New York - Broadway"
  21.                                                                 "39.745684,-104.998457"); // Via: "Denver"
  22.                                        
  23.                                         /* Lets read out some values... */
  24.                                         StringBuilder sb = new StringBuilder();
  25.                                         sb.append("Total Distance (meters): ").append(r.getDistanceMeters()).append("\n");
  26.                                         sb.append("Total Time (seconds): ").append(r.getDurationSeconds()).append("\n\n");
  27.                                         sb.append("First subroute: Locationname: ");
  28.                                         sb.append(r.getSubRoutes()[0].getEnd().getAdvancedAddress().getLocality()).append("\n");
  29.                                         sb.append("Lenght of first subroute (meters): ").append(r.getSubRoutes()[0].getLengthMeters()).append("\n");
  30.                                         sb.append("Overall Points in Polyline: ").append(r.getPolyLine().length);
  31.                                        
  32.                                         /* Show the values on the TextView. */
  33.                                         setTextOnUIThread(tv, sb.toString());
  34.                                 } catch (Exception e) {
  35.                                         /* Oops something went wrong... */
  36.                                         setTextOnUIThread(tv, "Error: " + e.getMessage());
  37.                                 }
  38.                         }
  39.         }).start();
  40.     }
  41.    
  42.     /** Simple helper function. */
  43.     private void setTextOnUIThread(final TextView t, final String s){
  44.         runOnUIThread(new Runnable(){
  45.                         @Override
  46.                         public void run() {
  47.                                 t.setText(s);
  48.                         }
  49.         });
  50.     }
  51. }
Parsed in 0.038 seconds, using GeSHi 1.0.8.4


License wrote:Image
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
Attachments
RouteSample.zip
Route-Sample ( 200kB )
(200.41 KiB) Downloaded 2899 times
Image
Image | Android Development Community / Tutorials
User avatar
plusminus
Site Admin
Site Admin
 
Posts: 2688
Joined: Wed Nov 14, 2007 8:37 pm
Location: Schriesheim, Germany

Top

Operation Time-Out Error

Postby brijeshthakur » Thu Jul 24, 2008 10:08 am

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.
brijeshthakur
Junior Developer
Junior Developer
 
Posts: 12
Joined: Wed Jul 23, 2008 12:36 pm
Location: Banglore,India

Postby stunti » Wed Oct 08, 2008 11:52 am

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.
stunti
Once Poster
Once Poster
 
Posts: 1
Joined: Wed Oct 08, 2008 11:47 am

I can´t make it run

Postby gustavo » Fri Nov 14, 2008 6:01 pm

Can you tell me how can I get com.google.googlenav package? My 1.0_r1 sdk version can't find it.
gustavo
Junior Developer
Junior Developer
 
Posts: 12
Joined: Sun Mar 02, 2008 2:55 pm

Draw path on the map

Postby zak » Fri Jan 09, 2009 5:30 pm

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!
Attachments
route.jpg
route.jpg (61.2 KiB) Viewed 30425 times
zak
Freshman
Freshman
 
Posts: 8
Joined: Tue Sep 23, 2008 8:42 am

Re: Operation Time-Out Error

Postby yorgosg » Wed Jan 21, 2009 4:46 pm

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 :(

is there an easier way of getting an app id?

can anyone help?
yorgosg
Developer
Developer
 
Posts: 35
Joined: Wed Jan 30, 2008 9:53 am

Top

Postby Tushaar » Fri Feb 27, 2009 4:24 pm

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 :)
Tushaar
Freshman
Freshman
 
Posts: 2
Joined: Fri Feb 27, 2009 4:19 pm
Location: pune,India

Postby linkmaster_6 » Mon Mar 09, 2009 11:02 pm

So is this made for sdk 1.0? or is that a no? is there no easy way to construct a path?
linkmaster_6
Experienced Developer
Experienced Developer
 
Posts: 51
Joined: Thu Oct 16, 2008 8:52 pm

Postby ashish » Thu Mar 12, 2009 10:07 am

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...............
ashish
Experienced Developer
Experienced Developer
 
Posts: 62
Joined: Fri Feb 20, 2009 8:09 am

Postby csie-tw » Sun Jun 21, 2009 11:35 am

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/and ... -path.html


Image
csie-tw
Freshman
Freshman
 
Posts: 2
Joined: Sun Jun 21, 2009 11:24 am

Postby xenon » Thu Jun 25, 2009 2:33 pm

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/and ... -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.
xenon
Freshman
Freshman
 
Posts: 2
Joined: Thu Jun 11, 2009 6:11 pm

Postby zpk1234 » Sun Jun 28, 2009 7:36 am

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/and ... -path.html


Image


but i cann't open the link
http://csie-tw.blogspot.com/2009/06/and ... -path.html
zpk1234
Junior Developer
Junior Developer
 
Posts: 22
Joined: Sat Jun 27, 2009 1:17 pm

Postby arvind » Thu Jul 02, 2009 10:40 am

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....
arvind
Junior Developer
Junior Developer
 
Posts: 21
Joined: Tue Jun 23, 2009 4:44 am
Location: Mumbai,India

Postby zpk1234 » Thu Jul 02, 2009 2:49 pm

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!
zpk1234
Junior Developer
Junior Developer
 
Posts: 22
Joined: Sat Jun 27, 2009 1:17 pm

Finding route using google API

Postby Hendry » Wed Oct 06, 2010 10:32 am

Hi .,

I am doing one google map application.
Is it possible to get route(direction) between two locations(given from and to lat/long) using GOOGLE API?
Thanks in advance :)
Hendry
Once Poster
Once Poster
 
Posts: 1
Joined: Wed Oct 06, 2010 10:23 am

Top
Next

Return to Map Tutorials

Who is online

Users browsing this forum: No registered users and 3 guests