Google Driving Directions - MapView overlayed

Tutorials that use the MapActivity. Many using GPS functionality.

How to use Driving Directions in mc5 release?

Postby tv_sathish » Wed Mar 05, 2008 6:32 pm

Hi all,
I tried using this DrivngDirections project but I am not able to see any route in the map? Why is it so? Also is there a default key to zoom the map? If I click the map, somtimes it shows the "Pin" symbol but I am not able to figure when it shows that symbol and on what basis? How can I see the driving directions on the map? I am able to see the time and distance indicators on the left after some time, though.

I saw somewhere else (in some example) of mc5 release, showing Driving Directions like instructions (Turn left, go straight 50 miles etc.)? Is there any new API that does this? Please help me how to achieve this?

How to use DrivingDirection.getFormattedDistance and DrivingDirection.getFormattedTime to get the actual distance and time (values, integer or date values), by say, parsing the string output returned by these methods? What are the default formats for these 2 meaurements? In this project, "Time : " in DrivingDirection.getFormattedTime is replaced with "". That means there is a default format for these two? what is that?

Thanks and regards,
TVP
tv_sathish
Developer
Developer
 
Posts: 29
Joined: Wed Jan 09, 2008 12:32 pm

Top

Re: How to use Driving Directions in mc5 release?

Postby plusminus » Wed Mar 05, 2008 8:18 pm

Hello tv_sathish,

tv_sathish wrote:Hi all,
I tried using this DrivngDirections project but I am not able to see any route in the map? Why is it so? Also is there a default key to zoom the map? If I click the map, somtimes it shows the "Pin" symbol but I am not able to figure when it shows that symbol and on what basis? How can I see the driving directions on the map? I am able to see the time and distance indicators on the left after some time, though.


If you copy-pasted the code, it will work. (You may have to pan the Map once, to get the first redraw done)

Since m5 there are so called LongClickListener, which i.e. the MapView (and the Browser) use. I also took me some crazy tries to figure out how to get the zoomer visible ^^

tv_sathish wrote:I saw somewhere else (in some example) of mc5 release, showing Driving Directions like instructions (Turn left, go straight 50 miles etc.)? Is there any new API that does this? Please help me how to achieve this?


Was it this you were seeing: http://andnav.anddev.org/ ;)
The Driving-Directions also provide the turns to make. (I think it was sth like ".getTurns()").

tv_sathish wrote:How to use DrivingDirection.getFormattedDistance and DrivingDirection.getFormattedTime to get the actual distance and time (values, integer or date values), by say, parsing the string output returned by these methods? What are the default formats for these 2 meaurements? In this project, "Time : " in DrivingDirection.getFormattedTime is replaced with "". That means there is a default format for these two? what is that?


There currently is no other way to get these values directly.
I calculate the lenght of the route, by calculating the lenght of each route-segment.
For time I have to make approximations.

Regards,
plusminus
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

DrivingDirections on map related issuee...(contd.)

Postby tv_sathish » Thu Mar 06, 2008 6:36 pm

Hi Plusminus,
Thanks a lot for your help. I tried getTurns(). What I want to know from you is whether getTurns() also returns normal directions (i.e. walking straight paths like "Walk 50 miles down XXX highway", etc., and not just turning instructions as it name suggests)? To me it appears to give all instructions (even non-turns), but I just thought of getting confirmed with you? Can you confirm this?

1. My driving directions are still not visible on the map in the project mentioned in this topic. I am attaching the
JPEG, it is not showing any further than that (as I told you, the PIN mark and the distance and time values on
the left). As I have not changed anything in your code, I am not sending code portions, but if you want to
verify, do let me know and I will send them. I am not seeing any directions. What is the problem?
2. How to add vertical scrollbars to your ListView?
3. How to set the position of the dialog? How to change background color/text color of dialog and ListView (not very urgent, but
interested to know)?

Thanks and regards,
TVP (tv_sathish) (you can refer me by TVP - short name for typing convenience :D )
Attachments
DD.JPG
DD.JPG (57.63 KiB) Viewed 11160 times
tv_sathish
Developer
Developer
 
Posts: 29
Joined: Wed Jan 09, 2008 12:32 pm

Postby plusminus » Fri Mar 07, 2008 12:16 am

Hello tvp ;),

yes, it returns only Turns.

1. Did you debug :?: Does the Path get filled and canvas.drawPath(...,...); get called :?:
2/3. Is there a ListView in this app :?

Regards,
plusminus
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

Issues (contd.)..

Postby tv_sathish » Fri Mar 07, 2008 7:27 pm

Hi Plusminus,
The DrivingDirections.getTurns does show something like "Head south toward..", "Merge onto ...", Take the State Hwy..."". Are you sure the Turns gives you only Turns related instructions? If so, can you share with me how to then get the directions for all the other instructions (i.e. all non-turn instructions)?

For the Overlay problem, the "draw" method's first line itself is not reached by the debugger, but I see the PIN and the distance/time values? How this is possible? could this be due to network slowness? Can you give me a screenshot of how the path will show if everything works well?

I have only a Dialog and TextView and I want to add scroll for the TextView and to be able to set Font color/Background color etc.? Do you know how to set scroll for TextView and how to set the Font color(background color I tried and it worked) for any View?

Do you know how to set some option with Spinner (not getting, but setting programmatically)? How to also not react to spinner clicks? I tried spinner.setOnItemSelectedListener(null), but it didn't work?

Why does the DrivingDirections fetch more than 4-5 seconds across a Dial-up network? Will Android team who test our contest entries be using a better network and can we assume that amount of network speed and write apps that use DrivingDirections?

Finally, I have a problem where I want to show something in a TextView and then after some time, say a few seconds, show a dialog. I have written the code like this:

Code: Select all
   mResultsArea.requestFocus();
   try {
        Thread.sleep(2000);
   } catch(Exception e) {}
   showDialog();


but what happens is that the TextView box itself gets filled only after 2 seconds and the dialog pops up immediately with it, quite not what I wanted. What could be the problem and how to solve it?

Thanks and regards,
TVP
tv_sathish
Developer
Developer
 
Posts: 29
Joined: Wed Jan 09, 2008 12:32 pm

Re: Issues (contd.)..

Postby plusminus » Sun Mar 09, 2008 1:41 pm

Hello tvp,

tv_sathish wrote:Hi Plusminus,
The DrivingDirections.getTurns does show something like "Head south toward..", "Merge onto ...", Take the State Hwy..."". Are you sure the Turns gives you only Turns related instructions?

Yes.
tv_sathish wrote:If so, can you share with me how to then get the directions for all the other instructions (i.e. all non-turn instructions)?

That is not provided by the DrivingDirections. (maybe in the future ??)

tv_sathish wrote: For the Overlay problem, the "draw" method's first line itself is not reached by the debugger, but I see the PIN and the distance/time values? How this is possible?

Sounds really strange.
tv_sathish wrote: could this be due to network slowness?

No.
tv_sathish wrote: Can you give me a screenshot of how the path will show if everything works well?
See page 1 of this topic.


tv_sathish wrote: I have only a Dialog and TextView and I want to add scroll for the TextView and to be able to set Font color/Background color etc.? Do you know how to set scroll for TextView and how to set the Font color(background color I tried and it worked) for any View?

Search for ScrollView :?:
This topic is not the right place for such a question!

tv_sathish wrote: Do you know how to set some option with Spinner (not getting, but setting programmatically)? How to also not react to spinner clicks? I tried spinner.setOnItemSelectedListener(null), but it didn't work?

This topic is not the right place for such a question!

tv_sathish wrote: Why does the DrivingDirections fetch more than 4-5 seconds across a Dial-up network? Will Android team who test our contest entries be using a better network and can we assume that amount of network speed and write apps that use DrivingDirections?

I don't know why it takes ""so long"" but expect at least the same delay on an actual device :!: You can simulate such delay and speeds in the DDMS-View.

tv_sathish wrote: Finally, I have a problem where I want to show something in a TextView and then after some time, say a few seconds, show a dialog. I have written the code like this:

Code: Select all
   mResultsArea.requestFocus();
   try {
        Thread.sleep(2000);
   } catch(Exception e) {}
   showDialog();


but what happens is that the TextView box itself gets filled only after 2 seconds and the dialog pops up immediately with it, quite not what I wanted. What could be the problem and how to solve it?

Remember: Do not send the UI-Thread to sleep :!: Why :?: Because the user gets pissed of :!:
Strange, perhaps add a Log.e to the catch-block and check if any Exception gets thrown.

Regards,
plusminus
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

Regarding DrivingDirections...(contd.)

Postby tv_sathish » Mon Mar 10, 2008 2:41 pm

Hi Plusminus,
Would you be able to share how you have managed to show non-Turn instructions in your project? I see that a loop through dd.getFeature(<>) returns all objects as Turn objects. How are u managing to show other non-Turn directions?

If sleeping within main thread isn't advisable, is there a method by which I can show some View after a small delay after displaying current view?

Basically I didn't want to start another post on Scrolling in case nobody replied. Also I felt it may be inconvenient for you too to open many posts and reply. That's why I added the doubts there itself. Anyway I shall follow what u said. But bear with me this time, I have one more just one-liner question that may not be suitable for this topic - how to receive all large amounts of data (I saw related posts but could not figure out how to do this) - through the android.net.RequestQueue mechanism? Data from server is cut halfway (after some <6K bytes) - full HTTP response not coming?

Thanks and regards
tv_sathish
Developer
Developer
 
Posts: 29
Joined: Wed Jan 09, 2008 12:32 pm

Re: Regarding DrivingDirections...(contd.)

Postby plusminus » Mon Mar 10, 2008 9:56 pm

tv_sathish wrote:Hi Plusminus,
Would you be able to share how you have managed to show non-Turn instructions in your project? I see that a loop through dd.getFeature(<>) returns all objects as Turn objects. How are u managing to show other non-Turn directions?

I'm not showing additional "non-turn-directions" :!:
Just what is returned in
Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. myDrivingDirection.getTurnText(int index);
Parsed in 0.030 seconds, using GeSHi 1.0.8.4


tv_sathish wrote: If sleeping within main thread isn't advisable, is there a method by which I can show some View after a small delay after displaying current view?

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. myHandler.postDelayed(Runnable r, int delay);
Parsed in 0.031 seconds, using GeSHi 1.0.8.4


tv_sathish wrote: Basically I didn't want to start another post on Scrolling in case nobody replied. Also I felt it may be inconvenient for you too to open many posts and reply. That's why I added the doubts there itself. Anyway I shall follow what u said. But bear with me this time, I have one more just one-liner question that may not be suitable for this topic - how to receive all large amounts of data (I saw related posts but could not figure out how to do this) - through the android.net.RequestQueue mechanism? Data from server is cut halfway (after some <6K bytes) - full HTTP response not coming?

Hm I don't know why it is cut of. Maybe it is a bug.

Anyway RequestQueue is preferable as it is asynchronous. There also is a :src: synchronous way. If you put that to a Thread its no problem anyway.

Regards,
plusminus
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

Postby jdoubleu » Mon Mar 24, 2008 3:31 am

plusminus,

Thanks for the helpful tutorial.

I am having the same experience as TVP. I am unable to see the path when the app loads, and I can see all of north america. If i drag on the map a bit, then i am able to see the 2 pushpins drawn right on top of each other over the san francisco bay area.

I added some stmts into the onCreate() method to zoom/center to one of the path endpoints, and i am now able to see the path better when the app first loads.

ctrl.zoomTo(9);
ctrl.centerMapTo(new Point(37423157, -122085008), true);


I am assuming that these calls would be necessary no? I mean to say that I'm surprised that it would work without them. Am I correct in my thinking?

One more question. Is there a way to programmatically "wiggle" the map so as to force the map to draw the route?

Thanks again,
jw
jdoubleu
Freshman
Freshman
 
Posts: 3
Joined: Sat Mar 01, 2008 11:30 pm
Location: New York City

Postby plusminus » Mon Mar 24, 2008 10:10 am

Hello jdoubleu,
jdoubleu wrote:I added some stmts into the onCreate() method to zoom/center to one of the path endpoints, and i am now able to see the path better when the app first loads.

ctrl.zoomTo(9);
ctrl.centerMapTo(new Point(37423157, -122085008), true);


I am assuming that these calls would be necessary no? I mean to say that I'm surprised that it would work without them. Am I correct in my thinking?

You can manually pan and zoom into the map, what leads to the same result in the end :!:

jdoubleu wrote:One more question. Is there a way to programmatically "wiggle" the map so as to force the map to draw the route?


Is [font=Lucida Console]wiggle ~ redraw[/font] :?:
:arrow:
Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. myMapView.invalidate();
Parsed in 0.033 seconds, using GeSHi 1.0.8.4


Regards,
plusminus
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

Postby Mick » Mon Mar 24, 2008 5:00 pm

Hello PlusMinus.
First of all, thanks a lot for helping us in discovering the android programming.

I want to improve this example (pretty good) by adding an animation along the route. I tried to do it like in the google website : http://code.google.com/android/referenc ... descr.html but with a ImageButton to stop the Button(the car), but I think there is problem with the overlay and my button doesn't appear on my map.

Nevertheless I know that your current work on AndNav must be kept secret, but if you have an idea to help me, i will be very happy ;).

Thanks a lot for all you do for the community.
Mick
Freshman
Freshman
 
Posts: 6
Joined: Mon Mar 24, 2008 9:59 am
Location: France

Postby jdoubleu » Mon Mar 24, 2008 6:03 pm

yes, panning causes the map to redraw, but in my case, the user will be confused if the directions don't just show up automatically.

Yes, by "wiggle" I meant a hack to programmatically pan a tiny bit to force the redraw, sounds like I should try that invalidate method tho. Thanks for the tip!

jw
jdoubleu
Freshman
Freshman
 
Posts: 3
Joined: Sat Mar 01, 2008 11:30 pm
Location: New York City

Postby inter » Mon Mar 24, 2008 7:20 pm

Hi everyone. The program above to me is not work .I'm using m5_rc15 .Why that ? the screen not see the PIN_END ,PIN_START ,not see the route path . I don't know when the method draw is called .Please someone can help me

Thanks
Regard
inter
Junior Developer
Junior Developer
 
Posts: 23
Joined: Thu Feb 21, 2008 10:13 am

Postby plusminus » Mon Mar 24, 2008 7:23 pm

Hello inter,

you see I attached 2 versions to the very first post of this topic (one for m3 and one for m5).
The m5 version is the 1:1 copy of my code, which is working.

draw() of the Overlay gets called everytime the map needs invalidation, i.e. when it was panned, zoomed, ...

Regards,
plusminus
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

Postby inter » Tue Mar 25, 2008 12:10 pm

Thank minus for reply quickly

When i debug the program above .I see that the method draw is called first when the program launch .But when i click the button "Show me the route " i think it will call the method draw ,but it doesn't call .Why that . how to call the method draw when i click the button "Show me the route"

i copied 1-1 your program ,but it's not work .

help me

thanks

regard
inter
Junior Developer
Junior Developer
 
Posts: 23
Joined: Thu Feb 21, 2008 10:13 am

Top
PreviousNext

Return to Map Tutorials

Who is online

Users browsing this forum: No registered users and 1 guest