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.

Xamarin.Forms.GoogleMaps.Bindings

Japanese Documents

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.

  1. Behavior for bind non-binding properties to View Model
  2. Behavior when events occur, execute ICommand
  3. Function for moving the map position from ViewModel

Setup

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());

Usage

Learn how to touch and pin any part of the map.  

  1. Create a new Xamarin forms project and make Xamarin.Forms.Maps available
    See here.
  2. Create MainPageViewModel.cs
  3. To modify MainPage.xaml

MainPageViewModel.cs

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
            });
        });
}

MainPage.xaml

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

License

See LICENSE.