Xamarin.Forms.GoogleMaps: Problem when many Pins to add (5.000 in my case)

VERSIONS

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

PLATFORMS

  • 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<MyModel> .
  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.

About this issue

  • Original URL
  • State: open
  • Created 6 years ago
  • Comments: 18 (2 by maintainers)

Most upvoted comments

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

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