Put your problem here if it does not fit any of the other categories.

Postby bavarol » Mon Mar 10, 2008 11:23 am

plusminus wrote:Its getting hot in here...
The mock-gps data is no following the planned route ;) :!:
Image


Anyone knows whether I can release any sources or previews when I plan to submit to the Android Challenge :?:

All the numbers (km and time) are static, expect the to be live ~tomorrow.

Regards,
plusminus

Hi PlusMinus, how do you draw the red line?
Do we need an aditional Layer to draw over? Or is it enough with drawing a line between previous and actual point?

I have tried to write but I cannot show anything :cry:

If you could write this little piece of code(only to draw the red line) I would be very happy.

Kind Regards ;) :cry:
bavarol
Experienced Developer
Experienced Developer
 
Posts: 52
Joined: Mon Dec 10, 2007 9:19 pm

Top

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

Hello bavarol,

the DrivingDirections provide the whole route, its our job to determine where we are (or not) on that route.
You'll need to do some linear algebra/geometry to determine your position on the route.
Tip: "Distance from point to line"

Having determined that point on the route it is easy to split the whole route into parts an paint the sections with different colors.

Btw: its a path not just a line.


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 bavarol » Tue Mar 11, 2008 2:21 pm

plusminus wrote:Hello bavarol,

the DrivingDirections provide the whole route, its our job to determine where we are (or not) on that route.
You'll need to do some linear algebra/geometry to determine your position on the route.
Tip: "Distance from point to line"

Having determined that point on the route it is easy to split the whole route into parts an paint the sections with different colors.

Btw: its a path not just a line.


Regards,
plusminus

Hi PlusMinus, ths for your fast answer, I explain you how I designed my app, I animate a point ("ME") and refresh GPS signal every 300milliseconds and 5 mts, I cannot use DrivingDirection Route because "ME" is a pedestrian therefore I put in a ArrayList of Location every gotten location of GPS and redraw the route but not how you think, I tried to do it with a Path object like you but It didn't work out, the I have tried to do it step(point) by step(point) and I got
Image: http://www.subirimagenes.com/imagen-de- ... 60560.html
Please help, it's more reasonable like you do it, therefore I asked you

Regards
bavarol
Experienced Developer
Experienced Developer
 
Posts: 52
Joined: Mon Dec 10, 2007 9:19 pm

Postby plusminus » Tue Mar 11, 2008 2:56 pm

Did you call [font=Lucida Console]myPath.moveTo(int x, int y)[/font] (sets where the path starts, default 0/0 ) before calling [font=Lucida Console]myPath.lineTo(int x, int y)[/font] :?:

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 bavarol » Tue Mar 11, 2008 3:51 pm

Now I show no route :(
bavarol
Experienced Developer
Experienced Developer
 
Posts: 52
Joined: Mon Dec 10, 2007 9:19 pm

Postby plusminus » Tue Mar 11, 2008 5:17 pm

Hello bovarol,

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. Path pathDone = new Path();
  2.  
  3. pathDone.moveTo(startX, startY);
  4.  
  5. pathDone.lineTo(..., ...);
  6.  
  7. pathDone.lineTo(..., ...);
  8.  
  9. pathDone.lineTo(..., ...);
  10.  
  11. pathDone.lineTo(..., ...);
  12.  
  13. /* Draw the pathDone route to the canvas. */
  14.  
  15. canvas.drawPath(pathDone, this.pathDonePaint);
Parsed in 0.031 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

Top

Postby bavarol » Tue Mar 11, 2008 6:30 pm

plusminus wrote:Hello bovarol,

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. Path pathDone = new Path();
  2. pathDone.moveTo(startX, startY);
  3. pathDone.lineTo(..., ...);
  4. pathDone.lineTo(..., ...);
  5. pathDone.lineTo(..., ...);
  6. pathDone.lineTo(..., ...);
  7. /* Draw the pathDone route to the canvas. */
  8. canvas.drawPath(pathDone, this.pathDonePaint);
Parsed in 0.031 seconds, using GeSHi 1.0.8.4


Regards,
plusminus

Hi,
I think I do what you have written, haven't I done it?

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1.                         /* Reset our paint. */
  2.                         this.pathPaint.setStrokeWidth(4);
  3.                         this.pathPaint.setARGB(100, 113, 105, 252);
  4.                         // holders of mapped coords...
  5.                         int[] screenCoords = new int[2];
  6.          
  7.                         Path thePath = new Path();
  8.                         thePath.moveTo(screenCoords[0], screenCoords[1]);
  9.                        
  10.                         for (Point currentPoint : path) {
  11.                                 /* Transform current Point's Lat/Lng
  12.                                  * into corresponding point on canvas
  13.                                  * using the pixelCalculator. */
  14.                                 calculator.getPointXY(currentPoint,screenCoords);
  15.                                 /* Add point to path. */
  16.                                 thePath.lineTo(screenCoords[0], screenCoords[1]); <- Here
  17.                         }
  18.                
  19.                         this.pathPaint.setStyle(Paint.Style.STROKE);
  20.                         /* Draw the actual route to the canvas. */
  21.                         canvas.drawPath(thePath, this.pathPaint);
Parsed in 0.036 seconds, using GeSHi 1.0.8.4
bavarol
Experienced Developer
Experienced Developer
 
Posts: 52
Joined: Mon Dec 10, 2007 9:19 pm

Postby plusminus » Tue Mar 11, 2008 6:59 pm

Hm... looking again at the screenshot I thought hat huge red thing could be the path, but it would be blue...

Did you debug your app and looked what values are written to screenCoords :?:

btw, I see a bug maybe:
Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1.                Path thePath = new Path(); // here THEPath
  2.  
  3.                thePath.moveTo(screenCoords[0], screenCoords[1]);
  4.  
  5.                
  6.  
  7.                for (Point currentPoint : path) { // here only path
Parsed in 0.036 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 bavarol » Wed Mar 12, 2008 3:36 pm

Hi,
I have written my code again, what I have is the following:
Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1.         public void draw(Canvas canvas, PixelCalculator calculator, boolean shadow) {
  2.           super.draw(canvas, calculator, shadow);
  3.          
  4.          
  5.           pathPaint.setStyle(Paint.Style.STROKE);
  6.           pathPaint.setStrokeWidth(6);
  7.           pathPaint.setColor(Color.RED);
  8.           pathPaint.setPathEffect(new CornerPathEffect(10));
  9.  
  10.  
  11.           Path thePath = new Path();
  12.           RectF bounds = new RectF();
  13.           thePath.computeBounds(bounds, false);
  14.          
  15.          
  16.           Point point = SimMapa.this.getStart();
  17.          
  18.           ArrayList<Point> route= SimMapa.this.getRoute();
  19.          
  20.          
  21.           int[] myScreenCoordinates = new int[2];
  22.           // We turn given point into screen Coordinates
  23.           calculator.getPointXY(point, myScreenCoordinates);
  24.          
  25.          //  -- BEGIN Graphical Debug Only for this purpose
  26.           RectF oval = new RectF(myScreenCoordinates[0] - 70, myScreenCoordinates[1] + 70,
  27.                   myScreenCoordinates[0] + 70, myScreenCoordinates[1] - 70);
  28.          
  29.           Paint paint = new Paint();
  30.           // We configure Paint of circle
  31.           paint.setStyle(Style.FILL);
  32.           paint.setARGB(80, 156, 192, 36);
  33.           paint.setStrokeWidth(4);
  34.           // We draw the circle
  35.           canvas.drawOval(oval, paint);
  36.         // -- END Graphical Debug
  37.          
  38.           thePath.moveTo(myScreenCoordinates[0], myScreenCoordinates[1]);
  39.            
  40.          
  41.           for (Point currentPoint : route) {
  42.  
  43.               // We turn the current point into ScreenCoordinates
  44.               calculator.getPointXY(currentPoint, myScreenCoordinates);
  45.  
  46.          //  -- BEGIN Graphical Debug Only for this purpose
  47.           RectF oval = new RectF(myScreenCoordinates[0] - 7, myScreenCoordinates[1] + 7,
  48.                   myScreenCoordinates[0] + 7, myScreenCoordinates[1] - 7);
  49.          
  50.           Paint paint = new Paint();
  51.           // We configure Paint of circle
  52.           paint.setStyle(Style.FILL);
  53.           paint.setARGB(80, 156, 192, 36);
  54.           paint.setStrokeWidth(4);
  55.           // We draw the circle
  56.           canvas.drawOval(oval, paint);
  57.         // -- END Graphical Debug
  58.                
  59.               thePath.lineTo(myScreenCoordinates[0],myScreenCoordinates[1]);                        
  60.            
  61.           }
  62.           canvas.drawPath(thePath,pathPaint);
  63.          
  64.        
  65.         }        
  66.                
  67.  
  68.     }
Parsed in 0.045 seconds, using GeSHi 1.0.8.4




The start point is in Africa!!!
Also, it's the red line thePath,Africa Point + first point of San Francisco
Image

San Francisco (step by step)
Image

How can my code compute and draw the red Line thePath before it can go step by step :shock: ?
It's a mistery.

Can you see an error?

Regards
bavarol
Experienced Developer
Experienced Developer
 
Posts: 52
Joined: Mon Dec 10, 2007 9:19 pm

Postby bavarol » Thu Mar 13, 2008 2:50 pm

Hi, the first point is the point of file "location", I have changed to the first point of the predefined route (San Francisco) of the emulator.
Good, I have debugged my app and the variable Path contains elements, also lines, but no path is shown.

I have tried to do the following

moveTo(5,5)
lineTo(10,10)
...

And I didn't get anything

What should I do?

Regards
bavarol
Experienced Developer
Experienced Developer
 
Posts: 52
Joined: Mon Dec 10, 2007 9:19 pm

Top

Return to Other Coding-Problems

Who is online

Users browsing this forum: No registered users and 19 guests