amay077 / Xamarin.Forms.GoogleMaps

Map library for Xamarin.Forms using Google maps API
https://www.nuget.org/packages/Xamarin.Forms.GoogleMaps/
MIT License
546 stars 349 forks source link

Problem when many Pins to add (5.000 in my case) #563

Open mcferdev opened 6 years ago

mcferdev commented 6 years ago

VERSIONS

PLATFORMS

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")
        };
  2. Then, I have a Api Call that returns a Json, that is a List .

  3. 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.

itoledo commented 6 years ago

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.

mcferdev commented 6 years ago

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 ?

itoledo commented 6 years ago

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?

amay077 commented 6 years ago

Please check out the issue #497 . And our sample app's code.

https://github.com/amay077/Xamarin.Forms.GoogleMaps/blob/4ab24797821e19768ebf89baa5c6896d4977f0af/XFGoogleMapSample/Droid/CachingNativeBitmapDescriptorFactory.cs

https://github.com/amay077/Xamarin.Forms.GoogleMaps/blob/4ab24797821e19768ebf89baa5c6896d4977f0af/XFGoogleMapSample/Droid/MainActivity.cs

mcferdev commented 6 years ago

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")
        };
mcferdev commented 6 years ago

Please check out the issue #497 . And our sample app's code.

https://github.com/amay077/Xamarin.Forms.GoogleMaps/blob/4ab24797821e19768ebf89baa5c6896d4977f0af/XFGoogleMapSample/Droid/CachingNativeBitmapDescriptorFactory.cs

https://github.com/amay077/Xamarin.Forms.GoogleMaps/blob/4ab24797821e19768ebf89baa5c6896d4977f0af/XFGoogleMapSample/Droid/MainActivity.cs

I already using it. Doesn´t work .

jvivas commented 6 years ago

Did you find a solution?

mcferdev commented 5 years ago

Did you find a solution?

No.

jocontacter commented 5 years ago

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

justwooper commented 5 years ago

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

BurakOgutken commented 5 years ago

i am same trouble did you find good solution @justwooper

amay077 commented 5 years ago

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

BurakOgutken commented 5 years ago

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

jocontacter commented 5 years ago

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

BurakOgutken commented 5 years ago

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

jocontacter commented 5 years ago

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?

dejanbasic commented 4 years ago

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

LittleBoxOfChicken commented 3 years ago

I'm trying to do this with a BitmapDescriptorFactory but I don't think that the factory itself is the problem in my case.

It seems that adding the pin to the map is a heavy, thread-blocking process on Android. On iOS it performs fine. Maybe the MainThread is held for code that it doesn't need to be held for?