[android-developers] Re: Maps API : drawing driving itinerary
Thanks for the responses. To TreKing : I quite clearly explained that the drawing area was where I needed to optimise. You can see that I trace the time taken here and this is where I can say that, on the emulator, it takes 18 seconds. to lbendlin : Thank you for the advice, I will do some further tests to see if this will affect the processing time. On Friday, 18 May 2012 02:16:47 UTC+2, lbendlin wrote: No need to worry about the screen pixels relative to your waypoints. The overlay manager handles that for you, and only renders the part that is on screen. Load all the points. On Thursday, May 17, 2012 12:19:33 PM UTC-4, Simon Giddings wrote: I am developing a maps application which will display a user defined driving itinerary. I obtain the driving directions from the Directions Web Service and parse the json response in a separate thread. I then hand the resulting itinerary object to my custom overlay for display. Before appending the overlay to the maps overlay list, I decode the polyline strings to obtain the coordinates. My drawing code obtains the projection object and draws out the line - this is taking 18 seconds ! ! ! Here is my code : @Override public void draw(Canvas cv, MapView view, boolean shadow) { GeoCoordsE6 point = null; // utility class holding a geopoint and a point class with a method to handle projection manipulation int iScreenWidth = view.getWidth(); int iScreenHeight = view.getHeight(); Paint paintLine = null;new Paint(); if(shadow) { super.draw(cv, view, shadow); return; } long lStartMs = android.os.SystemClock.uptimeMillis(); paintLine = new Paint(); paintLine.setColor(m_iLineClr); paintLine.setAntiAlias(true); paintLine.setStyle(Paint.Style.FILL_AND_STROKE); paintLine.setStrokeJoin(Paint.Join.ROUND); paintLine.setStrokeCap(Paint.Cap.ROUND); paintLine.setStrokeWidth(4); // get the projection to work with Projection pj = view.getProjection(); // get the first lat/lng position point = m_ItinLine.item(0); // convert the coorinates to screen pixels point.ResolvePosition(pj); // store the start position m_ptStart.x = point.m_pt.x; m_ptStart.y = point.m_pt.y; // now walk through the array list for(int i = 1; i m_ItinLine.count(); i++) { point = m_ItinLine.item(i); point.ResolvePosition(pj); m_ptEnd.x = point.m_pt.x; m_ptEnd.y = point.m_pt.y; if(m_ptStart.x 0 m_ptEnd.x 0 ||// to the left m_ptStart.y 0 m_ptEnd.y 0 ||// above the top m_ptStart.x iScreenWidth m_ptEnd.x iScreenWidth ||// to the right m_ptStart.y iScreenHeight m_ptEnd.y iScreenHeight)// below the bottom { // ignore the drawing } else if(m_ptStart.x == m_ptEnd.x m_ptStart.y == m_ptEnd.y) continue; else { cv.drawLine(m_ptStart.x, m_ptStart.y, m_ptEnd.x, m_ptEnd.y, paintLine); } m_ptStart.x = m_ptEnd.x; m_ptStart.y = m_ptEnd.y; } long lEndMs = android.os.SystemClock.uptimeMillis(); Log.d(ItineraryOverlay, Drawing took + (lEndMs - lStartMs) + ms); super.draw(cv, view, shadow); } Knowing that a number of people have done similar tasks, can anyone advise me as to how to improve the performance ? Should I be building a path object and fill it with ALL of the points ? -- You received this message because you are subscribed to the Google Groups Android Developers group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en
Re: [android-developers] Re: Maps API : drawing driving itinerary
On Fri, May 18, 2012 at 1:40 AM, Simon Giddings mr.s.giddi...@gmail.comwrote: To TreKing : I quite clearly explained that the drawing area was where I needed to optimise. You can see that I trace the time taken here and this is where I can say that, on the emulator, it takes 18 seconds. Your draw method is fairly big. There are a lot of steps there, including a loop where you iterate through a bunch of points (the number of which you didn't specify, which might be your issue). You time nearly the entire method, but more than likely there is one or two lines in there that are eating up the bulk of that time. My suggestion to you was to profile your code so you can narrow down more precisely which part(s) of that block of code is where most of your time is being spent. If you can come back and say this line in particular is killing me, or l'm looping through 6,000 points each frame, then it will be easier to get help with optimizing. - TreKing http://sites.google.com/site/rezmobileapps/treking - Chicago transit tracking app for Android-powered devices -- You received this message because you are subscribed to the Google Groups Android Developers group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en
Re: [android-developers] Re: Maps API : drawing driving itinerary
On Fri, May 18, 2012 at 4:00 AM, Simon Giddings mr.s.giddi...@gmail.comwrote: Here I loop through 11235 GeoPoint objects That seems like a lot in one draw call. So the next question is, do you need to draw lines between 11,235 points every frame? Before you get to the actual drawing, you should reduce that list size to the absolute minimum required to get your results. - TreKing http://sites.google.com/site/rezmobileapps/treking - Chicago transit tracking app for Android-powered devices -- You received this message because you are subscribed to the Google Groups Android Developers group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en
[android-developers] Re: Maps API : drawing driving itinerary
Try the Douglas-Peucker algorithm. There is an open-source implementation of the Douglas-Peucker algorithm in Java in the MyTracks Android project, which is licensed under Apache 2.0: http://code.google.com/p/mytracks/source/browse/MyTracks/src/com/google/android/apps/mytracks/util/LocationUtils.java Its in the method decimate(). On May 18, 10:06 am, TreKing treking...@gmail.com wrote: On Fri, May 18, 2012 at 4:00 AM, Simon Giddings mr.s.giddi...@gmail.comwrote: Here I loop through 11235 GeoPoint objects That seems like a lot in one draw call. So the next question is, do you need to draw lines between 11,235 points every frame? Before you get to the actual drawing, you should reduce that list size to the absolute minimum required to get your results. - TreKing http://sites.google.com/site/rezmobileapps/treking - Chicago transit tracking app for Android-powered devices -- You received this message because you are subscribed to the Google Groups Android Developers group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en
[android-developers] Re: Maps API : drawing driving itinerary
No need to worry about the screen pixels relative to your waypoints. The overlay manager handles that for you, and only renders the part that is on screen. Load all the points. On Thursday, May 17, 2012 12:19:33 PM UTC-4, Simon Giddings wrote: I am developing a maps application which will display a user defined driving itinerary. I obtain the driving directions from the Directions Web Service and parse the json response in a separate thread. I then hand the resulting itinerary object to my custom overlay for display. Before appending the overlay to the maps overlay list, I decode the polyline strings to obtain the coordinates. My drawing code obtains the projection object and draws out the line - this is taking 18 seconds ! ! ! Here is my code : @Override public void draw(Canvas cv, MapView view, boolean shadow) { GeoCoordsE6 point = null; // utility class holding a geopoint and a point class with a method to handle projection manipulation int iScreenWidth = view.getWidth(); int iScreenHeight = view.getHeight(); Paint paintLine = null;new Paint(); if(shadow) { super.draw(cv, view, shadow); return; } long lStartMs = android.os.SystemClock.uptimeMillis(); paintLine = new Paint(); paintLine.setColor(m_iLineClr); paintLine.setAntiAlias(true); paintLine.setStyle(Paint.Style.FILL_AND_STROKE); paintLine.setStrokeJoin(Paint.Join.ROUND); paintLine.setStrokeCap(Paint.Cap.ROUND); paintLine.setStrokeWidth(4); // get the projection to work with Projection pj = view.getProjection(); // get the first lat/lng position point = m_ItinLine.item(0); // convert the coorinates to screen pixels point.ResolvePosition(pj); // store the start position m_ptStart.x = point.m_pt.x; m_ptStart.y = point.m_pt.y; // now walk through the array list for(int i = 1; i m_ItinLine.count(); i++) { point = m_ItinLine.item(i); point.ResolvePosition(pj); m_ptEnd.x = point.m_pt.x; m_ptEnd.y = point.m_pt.y; if(m_ptStart.x 0 m_ptEnd.x 0 ||// to the left m_ptStart.y 0 m_ptEnd.y 0 ||// above the top m_ptStart.x iScreenWidth m_ptEnd.x iScreenWidth ||// to the right m_ptStart.y iScreenHeight m_ptEnd.y iScreenHeight)// below the bottom { // ignore the drawing } else if(m_ptStart.x == m_ptEnd.x m_ptStart.y == m_ptEnd.y) continue; else { cv.drawLine(m_ptStart.x, m_ptStart.y, m_ptEnd.x, m_ptEnd.y, paintLine); } m_ptStart.x = m_ptEnd.x; m_ptStart.y = m_ptEnd.y; } long lEndMs = android.os.SystemClock.uptimeMillis(); Log.d(ItineraryOverlay, Drawing took + (lEndMs - lStartMs) + ms); super.draw(cv, view, shadow); } Knowing that a number of people have done similar tasks, can anyone advise me as to how to improve the performance ? Should I be building a path object and fill it with ALL of the points ? -- You received this message because you are subscribed to the Google Groups Android Developers group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en