Xamarin.forms.googlemaps: Problem when many Pins to add (5.000 in my case)

Created on 3 Oct 2018  Â·  17Comments  Â·  Source: amay077/Xamarin.Forms.GoogleMaps

VERSIONS

  • Xamarin.Forms.GoogleMaps - 3.0.3
  • Xamarin.Forms - 3.2.0
  • Xamarin.GooglePlayServices.Maps - 60.1142.1

PLATFORMS

  • [x] Android
  • [ ] iOS
  • [ ] UWP

ACTUAL BEHAVIOR

When the list of pins is too long, the app lock. For instance, I have a Collection of Pins "A" that has 500 elements on list... works normally. Another Collection of Pins "B" has almost 5.000 pins. The app lock when start to Add the pins. Nothing happens. Any exception or error...just frozen.

EXPECTED BEHAVIOR

All the pins on the map.

HOW TO REPRODUCE

  1. Create a custom Pin
Pin pinOndeTemTiro = new Pin()
        {
            Type = PinType.Place,
            Icon = BitmapDescriptorFactory.FromBundle("ondetemtiro.png")
        };
  1. Then, I have a Api Call that returns a Json, that is a List .
  2. I get this List and try to populate on the Map.
 mylist = t.Result;

                        for (int index = 0; index < mylist.Count; index++)
                        {
                            try
                            {
                                var item = mylist[index];
                                var obj = item.latlng;
                                var LATLONG = JsonConvert.DeserializeObject<LatLong>(obj);
                                mylist[index].Latlong = LATLONG;

                                pinOndeTemTiro.Label = mylist[index].DsObjeto;
                                pinOndeTemTiro.Address = mylist[index].NmInformacao;
                                pinOndeTemTiro.Position = new Position(mylist[index].Latlong.Lat, mylist[index].Latlong.Lng);

                                map.Pins.Add(pinOndeTemTiro);

                            }
                            catch (Exception ex)
                            {

                            }
                        }

But, how I told, when has 500 items works nicelly. But when has almost 5.000 , locks and nothing happens.

help wanted

All 17 comments

I guess you should reuse your BitmapDescriptor instead of creating the same one for each pin.
Also, in your loop you should create a new instance of Pin on every iteration.

I guess you should reuse your BitmapDescriptor instead of creating the same one for each pin.
Also, in your loop you should create a new instance of Pin on every iteration.

Serious? Don´t you think will be slower ?

Well, adding the same object to a collection many times is wrong, unless you want to add the exact same instance of the object (same labels, position, …) to the Pins collection?

Well, adding the same object to a collection many times is wrong, unless you want to add the exact same instance of the object (same labels, position, …) to the Pins collection?

Well, but thats the point. If the Image and others parameters are the same, why create another collection ? I am creating a collection of Pins A that has differents labels and positions, but same Image A ...then a collection of Pins B with different labels and positions, but same image B... and continuous

 Pin pinApreensaoFuzil = new Pin()
        {
            Tag = "fuzil",
            Type = PinType.Place,
            Label = "Apreensão Fuzil",
            Icon = BitmapDescriptorFactory.FromBundle("apreensaofuzil.png")
        };

Did you find a solution?

Did you find a solution?

No.

Did you find a solution?

No.

Try to use pin aggregation depended on altitude(zoom). Group some near pins to one pin with count label of pins inside it. When you zoom in - groups becomes less and scattered

Did you find a solution?

No.

Try to use pin aggregation depended on altitude(zoom). Group some near pins to one pin with count label of pins inside it. When you zoom in - groups becomes less and scattered

could you write some code as example of doing this explanation? I have the same problem and I want to reduce time of drawing so many pins in map

i am same trouble did you find good solution @justwooper

I don't know why you should show 5000+ pin in map/screen?
Could you tell me your use case?

Me over 500+ this is vehicle tracking system but we need plate number over the pin @ammay077

Did you find a solution?

No.

Try to use pin aggregation depended on altitude(zoom). Group some near pins to one pin with count label of pins inside it. When you zoom in - groups becomes less and scattered

could you write some code as example of doing this explanation? I have the same problem and I want to reduce time of drawing so many pins in map

If you don't want to use aggregation, check your caching. This library has some problems with it.
Check this, maybe it is your case. But it is about BitmapDescriptorFactory.FromView() laggs. I don't know how good caching optimized with BitmapDescriptorFactory.FromBundle(). Sorry for my bad english

Hello i solved my problem with SkiaSharp i tested 1000 pins without any performans issue..

but i dont understand why android has this solution xamarin forms doesnt have

Hello i solved my problem with SkiaSharp i tested 1000 pins without any performans issue..

but i dont understand why android has this solution xamarin forms doesnt have

how did skia helped to you? Can you show piece of code?

Hey @BurakOgutken could you please share your solution with us?

Was this page helpful?
0 / 5 - 0 ratings

Related issues

LukasThijs picture LukasThijs  Â·  7Comments

woellij picture woellij  Â·  4Comments

non335 picture non335  Â·  7Comments

galadril picture galadril  Â·  3Comments

goodguy010 picture goodguy010  Â·  5Comments