themronion / Maui.GoogleMaps

Map library for MAUI using Google maps API
https://www.nuget.org/packages/Onion.Maui.GoogleMaps/
MIT License
79 stars 35 forks source link

ItemsSource binding doesn't work #45

Open RsZoli opened 5 months ago

RsZoli commented 5 months ago

VERSIONS

IDE

PLATFORMS

ACTUAL BEHAVIOR

When using the map control in XAML like this: <maps:Map x:Name="Map_Vonat" ItemsSource="{Binding Pins}" /> after populating the Pins property, nothing shows up on the map. The Pins property like this: public ObservableCollection<Pin> Pins { get; set; } and i'm populating it like this: _vm.Pins.Add(new Pin { Position = new Position(station_lat, station_lon), Icon = BitmapDescriptorFactory.FromBundle("map_station"), Label = station.Name });

However if i don't use ItemsSource, just add the Pins directly to the Map object, it works: Map_Vonat.Pins.Add(_vm.Pins.LastOrDefault());

ACTUAL SCREENSHOTS/STACKTRACE

n/a

EXPECTED BEHAVIOR

ItemsSource binding should work

HOW TO REPRODUCE

[code and steps to reproduce]

  1. Add the Map control to a XAML page
  2. Set the ItemsSource binding to a property in your VM
  3. Populate said property
andersonvieiragomeslopes commented 5 months ago

Hi @RsZoli.

I noticed the same problem, but with this behavior things started to work and I was able to maintain the code a little better with better practices with mvvm.

https://github.com/Charlygrind/Maui.GoogleMaps.Bindings

RsZoli commented 5 months ago

@andersonvieiragomeslopes Thank you, it works, however it only works on the main thread which kind of defeats its purpose!

andersonvieiragomeslopes commented 5 months ago

@andersonvieiragomeslopes Thank you, it works, however it only works on the main thread which kind of defeats its purpose!

The problem is in the collection and not in the component, really, if it is necessary to force the main thread to update the list, I even remove and add it again so that the item disappears from the list and the update happens. This problem has been happening since xamarin.forms. If everything is in the codebehind I believe it is not necessary to force the main thread. I have a real-time bike theft monitoring application and with each map update I am forced to force the mainthread or the list in the viewmodel will not update.

plppp2001 commented 5 months ago

@andersonvieiragomeslopes Thank you, it works, however it only works on the main thread which kind of defeats its purpose!

The problem is in the collection and not in the component, really, if it is necessary to force the main thread to update the list, I even remove and add it again so that the item disappears from the list and the update happens. This problem has been happening since xamarin.forms. If everything is in the codebehind I believe it is not necessary to force the main thread. I have a real-time bike theft monitoring application and with each map update I am forced to force the mainthread or the list in the viewmodel will not update.

What!? That's cool, what's your uri to your bike theft app? That sounds really cool...

andersonvieiragomeslopes commented 5 months ago

@andersonvieiragomeslopes Thank you, it works, however it only works on the main thread which kind of defeats its purpose!

The problem is in the collection and not in the component, really, if it is necessary to force the main thread to update the list, I even remove and add it again so that the item disappears from the list and the update happens. This problem has been happening since xamarin.forms. If everything is in the codebehind I believe it is not necessary to force the main thread. I have a real-time bike theft monitoring application and with each map update I am forced to force the mainthread or the list in the viewmodel will not update.

What!? That's cool, what's your uri to your bike theft app? That sounds really cool...

Hello @plppp2001

The application is not available yet, but if you are interested in more information, contact me through one of the contacts on my profile and I will send you images and explain more about my project. I would like to explain it here in this thread, but it's off topic, it would be better to talk elsewhere.