Wow, you are right, the new api gives no facility to do this... Its been a lot 
since i used google maps...

Well, only thing i can think now is to use two markers, one with the marker 
itself, using the image from a resource, and another one with the text, in this 
way you can measure the size of the text and create the bitmap of the exact 
size of the text and even using only bw colors (one bit per pixel, im not sure 
if android allowed this...) to use the minimum memory possible...

I will try to investigate if custom overlays can be done with v2.

Enviado desde mi iPad

El 04/07/2013, a las 20:03, Goncalo Oliveira <gonc...@minkan.net> escribió:

> API v1 had a way of doing this, there was an onDraw overridable for the 
> marker. I don't know how to do that in the current maps API version or if 
> it's even possible.
> 
> 
> On 4 July 2013 18:50, Agustín Giménez <geni...@gmail.com> wrote:
>> Well, md will eat some resources, so it may be a combination of too many 
>> bitmaps plus the md overhead...
>> 
>> A way to avoid this, is using custom overlays and draw it by yourself, load 
>> the initial bitmap in memory and on the draw of the overlay draw the image 
>> and the text, in this way you will not use any memory at all.
>> 
>> Enviado desde mi iPad
>> 
>> El 04/07/2013, a las 19:35, Goncalo Oliveira <gonc...@minkan.net> escribió:
>> L
>>> Augustin,
>>> 
>>> Thanks for replying. I actually did try to call Recycle and Dispose on the 
>>> bitmaps, also nulling instances and GC.Collect a bit. None of those worked. 
>>> And adding to the fact that it didn't work, it also slowed things a lot 
>>> (kind of expected).
>>> 
>>> However, I did went to the trouble of making a copy of the test case app in 
>>> Java using Android Studio and the results were very different. I was able 
>>> to display 1800 markers with custom bitmaps. So, yes, 900 markers is a lot 
>>> of juice but still, the expected behaviour was somewhat different. The 
>>> Xamarin - JVM bridge seems to be causing some struggle.
>>> 
>>> -- side note, Android Studio is kind of... very good... too bad it's Java.
>>> 
>>> Cheers.
>>> 
>>> 
>>> 
>>> On 4 July 2013 18:26, Agustín Giménez <geni...@gmail.com> wrote:
>>>> Hi.
>>>> 
>>>> I may be wrong, but I velibe its normal.
>>>> 
>>>> When you are giving a resource as bitmap, i think it will reuse the same 
>>>> bitmap all the time, so you have 900 markers, but only a bitmap. But with 
>>>> your function you are creating 900 bitmaps, so you are eating a lot of 
>>>> memory. Also you arent disposing anything, try to dispose all the 
>>>> resources you will not use and may be it will work.
>>>> 
>>>> Also a GC.Collect can help.
>>>> 
>>>> Hope it helps.
>>>> 
>>>> Enviado desde mi iPad
>>>> 
>>>> El 04/07/2013, a las 16:44, Goncalo Oliveira <gonc...@minkan.net> escribió:
>>>> 
>>>>> Hi,
>>>>> 
>>>>> I'm facing an issue with Google maps and custom bitmaps as marker icons 
>>>>> and I'm a little confused if I'm doing the thing the wrong way or there's 
>>>>> something wrong happening either with Google maps component or with the 
>>>>> Xamarin - JVM bridge.
>>>>> 
>>>>> 1. I'm placing a huge quantity of markers on the map. Let's start with 
>>>>> 900. I'm generating random locations around a point to create these much 
>>>>> different LatLng objects.
>>>>> 
>>>>> Next, I do the following for each LatLng item.
>>>>> 
>>>>>                 string title = "Item " + ( itemIndex++ ).ToString(); // 
>>>>> just for readability
>>>>> 
>>>>>                 var iconMarkerOption = new MarkerOptions()
>>>>>                 .SetPosition( item )
>>>>>                 .SetSnippet( "Snippet" )
>>>>>                 .Anchor( 0.5f, 0.5f )
>>>>>                 .SetTitle( title );
>>>>> 
>>>>>                 map.AddMarker( iconMarkerOption );
>>>>> 
>>>>> Build, Run and... all's well. 900 markers on the screen and not a care in 
>>>>> the world.
>>>>> 
>>>>> 2. I don't want to use the default image, to I change the code to use my 
>>>>> own.
>>>>> 
>>>>>                 var iconMarkerOption = new MarkerOptions()
>>>>>                 .SetPosition( item )
>>>>>                 .SetSnippet( "Snippet" )
>>>>>                 .Anchor( 0.5f, 0.5f )
>>>>>                 .InvokeIcon( BitmapDescriptorFactory.FromResource( 
>>>>> Resource.Drawable.ic_marker1 ) )
>>>>>                 .SetTitle( title );
>>>>> 
>>>>> Again, build, run and... all's well. 900 markers on the screen with my 
>>>>> own icon.
>>>>> 
>>>>> 3. I don't want just a standard image, I want to add some label text to 
>>>>> each icon. So I create the following method.
>>>>> 
>>>>>         private Paint paint = new Paint( PaintFlags.AntiAlias );
>>>>>         private Rect bounds = new Rect();
>>>>>         private BitmapDescriptor GetCustomBitmapDescriptor( string text )
>>>>>         {
>>>>>             Bitmap baseBitmap = BitmapFactory.DecodeResource( Resources, 
>>>>> Resource.Drawable.ic_marker1 );
>>>>>             Bitmap bitmap = baseBitmap.Copy( Bitmap.Config.Argb8888, true 
>>>>> );
>>>>> 
>>>>>             paint.GetTextBounds( text, 0, text.Length, bounds );
>>>>> 
>>>>>             float x = bitmap.Width / 2.0f;
>>>>>             float y = ( bitmap.Height - bounds.Height() ) / 2.0f - 
>>>>> bounds.Top;
>>>>> 
>>>>>             Canvas canvas = new Canvas( bitmap );
>>>>> 
>>>>>             canvas.DrawText( text, x, y, paint );
>>>>> 
>>>>>             BitmapDescriptor icon = BitmapDescriptorFactory.FromBitmap( 
>>>>> bitmap );
>>>>> 
>>>>>             return ( icon );
>>>>>         }
>>>>> 
>>>>> and I change my code
>>>>> 
>>>>>                 var iconMarkerOption = new MarkerOptions()
>>>>>                 .SetPosition( item )
>>>>>                 .SetSnippet( "Snippet" )
>>>>>                 .Anchor( 0.5f, 0.5f )
>>>>>                 .InvokeIcon( GetCustomBitmapDescriptor( title ) )
>>>>>                 .SetTitle( title );
>>>>> 
>>>>> Build, run and... out of memory.
>>>>> 07-04 15:32:35.055: E/mono(6005): Unhandled Exception:
>>>>> 07-04 15:32:35.055: E/mono(6005): Java.Lang.OutOfMemoryError: Exception 
>>>>> of type 'Java.Lang.OutOfMemoryError' was thrown.
>>>>> 07-04 15:32:35.055: E/mono(6005): at 
>>>>> Android.Runtime.JNIEnv.CallStaticObjectMethod 
>>>>> (intptr,intptr,Android.Runtime.JValue[]) <0x00080>
>>>>> 07-04 15:32:35.055: E/mono(6005): at 
>>>>> Android.Gms.Maps.Model.BitmapDescriptorFactory.FromBitmap 
>>>>> (Android.Graphics.Bitmap) <0x00103>
>>>>> 07-04 15:32:35.055: E/mono(6005): at 
>>>>> MapsExtensionsTest.MainActivity.GetCustomBitmapDescriptor (string) 
>>>>> <0x001b7>
>>>>> 07-04 15:32:35.055: E/mono(6005): at 
>>>>> MapsExtensionsTest.MainActivity.button_Click (object,System.EventArgs) 
>>>>> <0x00187>
>>>>> 07-04 15:32:35.055: E/mono(6005): at 
>>>>> Android.Views.View/IOnClickListenerImplementor.OnClick 
>>>>> (Android.Views.View) <0x0005b>
>>>>> 07-04 15:32:35.055: E/mono(6005): at 
>>>>> Android.Views.View/IOnClickListenerInvoker.n_OnClick_Landroid_view_View_ 
>>>>> (intptr,intptr,intptr) <0x0005b>
>>>>> 07-04 15:32:35.055: E/mono(6005): at (wrapper dynamic-method) 
>>>>> object.d67d7456-e896-445d-be35-db0b39982fc0 (intptr,intptr,intptr) 
>>>>> <0x00043>
>>>>> 07-04 15:32:35.055: E/mono(6005):   --- End of managed exception stack 
>>>>> trace ---
>>>>> 07-04 15:32:35.055: E/mono(6005): java.lang.OutOfMemoryError
>>>>> 07-04 15:32:35.055: E/mono(6005):         at 
>>>>> android.graphics.Bitmap.nativeCreateFromParcel(Native Method)
>>>>> 
>>>>> I tried changing the baseBitmap decoding to some place else, so that it's 
>>>>> only called once, as it's kind of lame to do this every single time.
>>>>> 
>>>>>         private Paint paint = new Paint( PaintFlags.AntiAlias );
>>>>>         private Rect bounds = new Rect();
>>>>>         Bitmap baseBitmap = null;
>>>>>         private BitmapDescriptor GetCustomBitmapDescriptor( string text )
>>>>>         {
>>>>>             if ( baseBitmap == null )
>>>>>             {
>>>>>                 baseBitmap = BitmapFactory.DecodeResource( Resources, 
>>>>> Resource.Drawable.ic_marker1 );
>>>>>             }
>>>>> 
>>>>>             Bitmap bitmap = baseBitmap.Copy( Bitmap.Config.Argb8888, true 
>>>>> );
>>>>> 
>>>>>             paint.GetTextBounds( text, 0, text.Length, bounds );
>>>>> 
>>>>>             float x = bitmap.Width / 2.0f;
>>>>>             float y = ( bitmap.Height - bounds.Height() ) / 2.0f - 
>>>>> bounds.Top;
>>>>> 
>>>>>             Canvas canvas = new Canvas( bitmap );
>>>>> 
>>>>>             canvas.DrawText( text, x, y, paint );
>>>>> 
>>>>>             BitmapDescriptor icon = BitmapDescriptorFactory.FromBitmap( 
>>>>> bitmap );
>>>>> 
>>>>>             return ( icon );
>>>>>         }
>>>>> 
>>>>> Build, run and... again, out of memory...
>>>>> 07-04 15:36:42.175: E/mono(6409): Java.Lang.OutOfMemoryError: Exception 
>>>>> of type 'Java.Lang.OutOfMemoryError' was thrown.
>>>>> 07-04 15:36:42.175: E/mono(6409): at 
>>>>> Android.Runtime.JNIEnv.CallObjectMethod 
>>>>> (intptr,intptr,Android.Runtime.JValue[]) <0x00080>
>>>>> 07-04 15:36:42.175: E/mono(6409): at Android.Graphics.Bitmap.Copy 
>>>>> (Android.Graphics.Bitmap/Config,bool) <0x00167>
>>>>> 07-04 15:36:42.175: E/mono(6409): at 
>>>>> MapsExtensionsTest.MainActivity.GetCustomBitmapDescriptor (string) 
>>>>> <0x00097>
>>>>> 07-04 15:36:42.175: E/mono(6409): at 
>>>>> MapsExtensionsTest.MainActivity.button_Click (object,System.EventArgs) 
>>>>> <0x00187>
>>>>> 07-04 15:36:42.175: E/mono(6409): at 
>>>>> Android.Views.View/IOnClickListenerImplementor.OnClick 
>>>>> (Android.Views.View) <0x0005b>
>>>>> 07-04 15:36:42.175: E/mono(6409): at 
>>>>> Android.Views.View/IOnClickListenerInvoker.n_OnClick_Landroid_view_View_ 
>>>>> (intptr,intptr,intptr) <0x0005b>
>>>>> 07-04 15:36:42.175: E/mono(6409): at (wrapper dynamic-method) 
>>>>> object.8ea9efe6-5373-404e-9980-0a2a1ca9397f (intptr,intptr,intptr) 
>>>>> <0x00043>
>>>>> 07-04 15:36:42.175: E/mono(6409):   --- End of managed exception stack 
>>>>> trace ---
>>>>> 07-04 15:36:42.175: E/mono(6409): java.lang.OutOfMemoryError
>>>>> 07-04 15:36:42.175: E/mono(6409):         at 
>>>>> android.graphics.Bitmap.nativeCopy(Native Method)
>>>>> 07-04 15:36:42.175: E/mono(6409):         at 
>>>>> android.graphics.Bitmap.copy(Bitmap.java:403)
>>>>> 07-04 15:36:42.175: E/mono(6409):         at 
>>>>> mono.android.view.View_OnClickListenerImplementor.n_onClick(Native Method)
>>>>> 07-04 15:36:42.175: E/mono(6409):         at mono.androi
>>>>> 
>>>>> What can I do to avoid this? If the Google maps can do this when using 
>>>>> the resource id directly, there has to be a way, right?...
>>>>> 
>>>>> Any thoughts on this would be highly appreciated.
>>>>> 
>>>>> Cheers.
>>>>> 
>>>>> 
>>>>> -- 
>>>>> Gonçalo Oliveira
>>>>> 
>>>>> _______________________________________________
>>>>> Monodroid mailing list
>>>>> Monodroid@lists.ximian.com
>>>>> 
>>>>> UNSUBSCRIBE INFORMATION:
>>>>> http://lists.ximian.com/mailman/listinfo/monodroid
>>>> 
>>>> _______________________________________________
>>>> Monodroid mailing list
>>>> Monodroid@lists.ximian.com
>>>> 
>>>> UNSUBSCRIBE INFORMATION:
>>>> http://lists.ximian.com/mailman/listinfo/monodroid
>>>> 
>>> 
>>> 
>>> 
>>> -- 
>>> Gonçalo Oliveira
>>> _______________________________________________
>>> Monodroid mailing list
>>> Monodroid@lists.ximian.com
>>> 
>>> UNSUBSCRIBE INFORMATION:
>>> http://lists.ximian.com/mailman/listinfo/monodroid
>> 
>> _______________________________________________
>> Monodroid mailing list
>> Monodroid@lists.ximian.com
>> 
>> UNSUBSCRIBE INFORMATION:
>> http://lists.ximian.com/mailman/listinfo/monodroid
>> 
> 
> 
> 
> -- 
> Gonçalo Oliveira
> _______________________________________________
> Monodroid mailing list
> Monodroid@lists.ximian.com
> 
> UNSUBSCRIBE INFORMATION:
> http://lists.ximian.com/mailman/listinfo/monodroid
_______________________________________________
Monodroid mailing list
Monodroid@lists.ximian.com

UNSUBSCRIBE INFORMATION:
http://lists.ximian.com/mailman/listinfo/monodroid

Reply via email to