| Author |
Message |
plusminus Site Admin

Joined: 14 Nov 2007 Posts: 2067 Location: Germany
|
Posted: Mon Apr 28, 2008 11:45 pm Post subject: Route - Improved Google Driving Directions |
|
|
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.
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:
| 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
| Description: |
|
 Download |
| Filename: |
RouteSample.zip |
| Filesize: |
200.41 KB |
| Downloaded: |
81 Time(s) |
_________________
| Android Development Community / Tutorials |
|
| Back to top |
|
 |
brijeshthakur Freshman
Joined: 23 Jul 2008 Posts: 4 Location: Banglore,India
|
Posted: Thu Jul 24, 2008 10:08 am Post subject: Operation Time-Out Error |
|
|
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 |
|
 |
|
|
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.
|