This maintenance is currently suspended.
This is because developers can't take the time because of private changes. If you are a new user, please consider fork and managing it yourself.
This library is the MVVM(Bindings) support library for Xamarin.Forms.GoogleMaps.
To support binding, Xamarin.Forms.GoogleMaps requires broken changes.
For this reason, major change to Xamarin.Forms.GoogleMaps to use it.
This library provides three types of functions.
- Behavior for bind non-binding properties to View Model
- Behavior when events occur, execute ICommand
- Function for moving the map position from ViewModel
- Available on NuGet: https://www.nuget.org/packages/Xamarin.Forms.GoogleMaps.Bindings
- Install into your PCL project only.
- Enable XAML Compilation
If you cannot enable XAML Compilation.
Add the following.
- Install the package to your Native project
- Add an initialization process
global::Xamarin.Forms.Forms.Init();
Xamarin.FormsGoogleMaps.Init(this, bundle);
Xamarin.FormsGoogleMapsBindings.Init(); // Add this line
LoadApplication(new App());
Learn how to touch and pin any part of the map.
- Create a new Xamarin forms project and make Xamarin.Forms.Maps available
See here. - Create MainPageViewModel.cs
- To modify MainPage.xaml
public class MainPageViewModel
{
public ObservableCollection<Pin> Pins { get; set; }
public Command<MapClickedEventArgs> MapClickedCommand =>
new Command<MapClickedEventArgs>(args =>
{
Pins.Add(new Pin
{
Label = $"Pin{Pins.Count}",
Position = args.Point
});
});
}
<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:googleMaps="clr-namespace:Xamarin.Forms.GoogleMaps;assembly=Xamarin.Forms.GoogleMaps"
xmlns:bindings="clr-namespace:Xamarin.Forms.GoogleMaps.Bindings;assembly=Xamarin.Forms.GoogleMaps.Bindings"
xmlns:local="clr-namespace:SimplestSample;assembly=SimplestSample"
x:Class="SimplestSample.MainPage">
<ContentPage.BindingContext>
<local:MainPageViewModel/>
</ContentPage.BindingContext>
<googleMaps:Map>
<googleMaps:Map.Behaviors>
<bindings:BindingPinsBehavior Value="{Binding Pins}"/>
<bindings:MapClickedToCommandBehavior Command="{Binding MapClickedCommand}"/>
</googleMaps:Map.Behaviors>
</googleMaps:Map>
</ContentPage>
BindingPinsBehavior binds the Pins property of the map to ViewModel Pins.
MapClickedToCommandBehavior handles the Mapclicked event and calls the ViewModel MapClickedCommand.
Behavior to bind the property supports only the OneWayToSource.
Otherwise please see samples here.
GoogleMaps.Bindings project.
See LICENSE.
- logo.png by alecive - CC BY-SA 4.0
- Android Icon made by Hanan from www.flaticon.com