2

This question is different than this another one So, I have been observed the native google maps app when it draw long ways on the map.

When the zoom is too far, the lines are not full of details ... I mean, when we use the google maps api and request for a path between two different points we receive the whole coordinates for draw the most detailed path on the map.

As we change the zoom the drawn lines receive more details.

The question is. Is there a way to do something like the native google maps app ? Can we ask for less details to draw the path on the map using google maps api ? Can we improve the lines drawn details as we change the zoom ?

If the answer is "no" for all of my questions, here you go another one: How can we draw a long path on map without lag issues ?

I hope I've be clear, sorry about my English.

Community
  • 1
  • 1
Leandro Silva
  • 804
  • 1
  • 9
  • 28

1 Answers1

1

Google Maps is probably a bitmap of that path generated by the server. A new one for every zoom level.

You can do something similar but it's quite some work. But it should be faster to generate a transparent bitmap once instead of drawing the path each time the view needs to refresh. You can also draw a path with reduced details if you simply skip some points but finding an algorithm that does not skip the important parts is quite tricky.

zapl
  • 63,179
  • 10
  • 123
  • 154
  • It sounds good. Do you know some algorithm to do it ? And where can I found how to generate a transparent bitmap instead drawing the path ? – Leandro Silva Apr 25 '12 at 15:51
  • Sorry, don't have an algorithm for that. And drawing into a `Bitmap` via a `Canvas` would be the way to create such a bitmap. There should be some examples here on SO – zapl Apr 25 '12 at 15:55
  • 1
    So, the point is draw the path only one time into a Bitmap and instead of draw line by line on map I only need to load it on the map, right ? The map will be able to keep this Bitmap on the right place ? – Leandro Silva Apr 25 '12 at 17:48
  • yes, you replace the code that draws line by code that draws the bitmap onto the map. Can't remember how that is done and how complicated it was but I did something like this once. – zapl Apr 25 '12 at 17:52
  • 1
    I tried to draw the Bitmap via Canvas on the method [onDraw](https://developers.google.com/maps/documentation/android/reference/com/google/android/maps/Overlay#draw%28android.graphics.Canvas,%20com.google.android.maps.MapView,%20boolean%29) but the results were the same =/ The performance also was huge affected adding a lot of bitmaps ... I think I will have to draw line by line and save them as only one bitmap ( I don't know how ) then I will be able to call this method just once. I don't know how to do and if it's possible :( – Leandro Silva May 02 '12 at 19:22
  • Yes if you draw the path with as many bitmaps as you use path segments then you get about the same or probably an even worse performance. The general approach to create a bitmap would be like: find max / min for each latitude / longitude of your path coordinates, convert those number so you have coordinates you can draw in bitmap coordinates (e.g. lat 5 .. 6 -> 0px - 100px, then 5.5 latitude is at 50px). In the end draw the bitmap as big as the coordiantes are (spanning from 5..6 in that example). And if bitmap is bigger than the part you see in the screen then draw only the required region – zapl May 02 '12 at 22:02