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 347 forks source link

Improved Binding Support #519

Closed dansiegel closed 5 years ago

dansiegel commented 6 years ago

SUMMARY

Working with the Map control should allow easy binding to a data set with a DataTemplate. This should work similar to a ListView in which you can bind to a generic set of data with a DataTemplate that produces a Pin to add to the controls Pin collection.

DETAILS

Two bindable properties should be added:

<maps:Map Items="{Binding MyLocations}">
  <maps:Map.ItemTemplate>
    <DataTemplate>
      <maps:Pin Label="{Binding Name}" 
                IsDraggable="false"
                Icon="{Binding SomeProp,Converter={StaticResource MyIconConverter}}">
        <maps:Pin.Position>
          <maps:Position Latitude="{Binding Latitude}"
                         Longitude="{Binding Longitude}" />
        </maps:Pin.Position>
      </maps:Pin>
    </DataTemplate>
  </maps:Map.ItemTemplate>
</maps:Map>

In addition, an event and Command should be added in the spirit of when a Pin is Selected.

When a Pin is selected the ItemSelected event should invoked and the Command executed with the BindingContext of each passed to them.

PLATFORMS

amay077 commented 6 years ago

Do you know Xamarin.Forms.GoogleMaps.Bindings ?

This is already implemented part of your request.

dansiegel commented 6 years ago

I am familiar with it... it should really be baked in though. Happy to send you a PR on this

amay077 commented 5 years ago

I supported ItemsSource and ItemTemplate in Xamarin.Forms.GoogleMaps v3.1.0+ .

Thanks @dansiegel ! 👍

gabrielbunselmeyer commented 5 years ago

Is there any documentation as far as using the DataTemplate part of the binding goes?

<maps:Map x:Name="mapView" ItemsSource="{Binding Pins}" AbsoluteLayout.LayoutBounds="0, 0, 1, 0.7" AbsoluteLayout.LayoutFlags="All">
                <maps:Map.ItemTemplate>
                    <DataTemplate>
                        <maps:Pin Label="teste" Address="address">
                            <maps:Pin.Position>
                                <maps:Position >

                                </maps:Position>
                            </maps:Pin.Position>
                        </maps:Pin>

                    </DataTemplate>
                </maps:Map.ItemTemplate>
            </maps:Map>

This is what I currently got, yet can't seem to figure out how to get Latitude and Longitude into it. doesn't seem to have that property in XAML.