[mono-android] Add a marker on Google Maps activity
Tomasz Cielecki
tomasz at ostebaronen.dk
Sat Dec 17 10:59:59 EST 2011
Oh! I just read my code again and that MyItemizedOverlay class is not
working just like that.
Everytime you add objects to the List of overlay items you need to
call Populate. Hence you will need to add the code:
public void AddOverlayItem(MyOverlayItem item)
{
overlayItems.Add(item);
Populate();
}
public void RemoveOverlayItem(MyOverlayItem item)
{
overlayItem.Remove(item);
Populate();
}
public List<MyOverlayItem> OverlayItems is a method I only use for
iterating on objects in the list for things such as centering the map
on an specific item or around all the items. It should not be used for
anything else! That is why you get an exception when Size() is called.
On Sat, Dec 17, 2011 at 4:30 PM, Tomasz Cielecki <tomasz at ostebaronen.dk> wrote:
> Hey there,
>
> Try using OverlayItem instead of MyOverlayItem. The member float[]
> color is not used for anything in MyOverlayItem in that sample.
>
> I have been messing around with Drawables on the OverlayItems and have
> found out that you have to set the bounds of the drawables before they
> show up.
>
> Like so:
>
> marker.Bounds = new Rect(0,0, <width>, <height>);
>
> where <width> and <height> of course have to be replaced with the
> actual height and width of the drawable.
>
> Which version of Mono for Android are you using, because the code only
> works with Mono for Android 4.0 and up. I also have a sample that
> works with 1.9.x.
>
> There also might be a bug in the methods BoundCenterBottom(Drawable
> drawable) and BoundCenter(Drawable drawable) in the ItemizedOverlay
> which I am investigating right now. That could possibly make the
> Drawables not appear to show up on the map.
>
> On Sat, Dec 17, 2011 at 8:47 AM, tequila slammer <buero at cayas.de> wrote:
>> I'm trying to add markers to a Google Maps activity. I tested some code
>> examples - mostly the ones from Tomasz Cielecki. The code I'm playing around
>> with is this basic example
>> https://github.com/Cheesebaron/MonoDroid.SimpleOverlayItem.
>>
>> It works as long as I do not try to set my own marker like this :
>>
>> <code>
>> var test = new MyOverlayItem(new GeoPoint(53, 09), "test", "test test", new
>> float[] { 121212 });
>> test.SetMarker(marker);
>>
>> myItemizedOverlay.OverlayItems.Add(test);
>> </code>
>>
>> The app always crashes unexpected right after I hit this method.
>>
>> public override int Size()
>> {
>> return overlayItems.Count;
>> }
>>
>> Can anybody point me in the right direction or can provide me with a working
>> code example?
>>
>> --
>> View this message in context: http://mono-for-android.1047100.n5.nabble.com/Add-a-marker-on-Google-Maps-activity-tp5082256p5082256.html
>> Sent from the Mono for Android mailing list archive at Nabble.com.
>> _______________________________________________
>> Monodroid mailing list
>> Monodroid at lists.ximian.com
>>
>> UNSUBSCRIBE INFORMATION:
>> http://lists.ximian.com/mailman/listinfo/monodroid
>
>
>
> --
> Med Venlig Hilsen / With Best Regards
> Tomasz Cielecki
> http://ostebaronen.dk
--
Med Venlig Hilsen / With Best Regards
Tomasz Cielecki
http://ostebaronen.dk
More information about the Monodroid
mailing list