GithubHelp home page GithubHelp logo

xamarin.forms.googlemaps.bindings's Introduction

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.

xamarin.forms.googlemaps.bindings's People

Contributors

amay077 avatar beej126 avatar damiendoumer avatar nuitsjp avatar pandazzurro avatar ryanrauch avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

xamarin.forms.googlemaps.bindings's Issues

load pin at the start

Hello,

I'm trying show pins at start with property Pins, however it does not work.

any solution? any example, please?

How MoveToRegion every 5000ms

Hi,

I want refresh every 5000ms my current position on map. I can MoveToRegion one time but when I use a Timer for MoveToRegion every 5000ms nothing happens.

Can you help me, to how move map to my current position every 5000ms?

Thanks,
BullT

InitialCameraUpdate

I can set InitialCameraUpdate="35.11, 54, 4.5, 0, 0" in xaml.
How can I do this by binding in ViewModel?

Doesn't work MoveToRegion in my ViewModel

Hi there, my problem is i can't move the map from my viewmodel, i followed the sample and i've tried this:

  1. In the Xaml of the project, i added this Behavior in my GoogleMap:
    <bindings:MoveToRegionBehavior Request="{Binding Request}"/>

  2. In the ViewModel i added this request:
    public MoveToRegionRequest Request { get; } = new MoveToRegionRequest();

  3. and later, in the same ViewModel, i created a method that is in the construct of the ViewModel, this has the next line of code:
    Request.MoveToRegion( MapSpan.FromCenterAndRadius( new Position(35.681298, 139.766247), Distance.FromKilometers(2)));

I guess that with this one my map can move to region but nothing happens, of course in my page i've called the behaviors and my ViewModel, what am I doing wrong?

Sorry for my English :)

How to use MoveToRegionRequest

Hi. Could someone tell me how to use MoveToRegionRequest?
I tried something like this:
<bindings:MoveCameraBehavior Request="{Binding MoveToRegionRequest}" />

And in code:
MoveToRegionRequest regionTemp = new MoveToRegionRequest(); regionTemp.MoveToRegion(new MapSpan(MapCenterPosition, 0, 0)); MoveToRegionRequest = regionTemp;
And prop:
` private MoveToRegionRequest moveToRegionRequest;

    public MoveToRegionRequest MoveToRegionRequest
    {
        get { return moveToRegionRequest; }
        set
        {
            moveToRegionRequest = value;
        }
    }`

But nothing happened. I want to move visibility to some region.

Value property marked as private set

Hi,

I write my UI in C# and I'm having some issues using the BindingPinsBehaviour. It has two properties available, BindingContext and Value.

Value seems to be a private set; but I can see you're setting it successfully in your XAML example.

new Map {
         Behaviors = {
                new BindingPinsBehavior {
                         Value = new Binding("Pins")
                 }
        },
}.Row(1).Bind(IsVisibleProperty, "MapViewVisible")

I'm being told Value is readonly--.

Thanks,
Sean

Pin Binding not working

Hello,

The binding on the Pins somehow doesn´t work.
I am getting this message in the output :
Binding: 'Pins' property not found on 'Controls.MapView', target property: 'Xamarin.Forms.GoogleMaps.Bindings.BindingPinsBehavior.Value'
However, all other bindings on the same XAML do work.

Any suggestions ?

XAML Snippet :

...
            <custom:MapView x:Name="MapLayer"  Grid.Row="0" Grid.Column="0" Grid.RowSpan="5">
                <custom:MapView.Behaviors>
                    <bindings:BindingPinsBehavior Value="{Binding Pins}"/>
                </custom:MapView.Behaviors>
            </custom:MapView>
...

Whereas MapView is a class that inherits form Xamarin.Forms.GoogleMaps.Map

The Property 'CameraUpdate' was not found in Type 'UpdateCameraPositionBehavior'

Hi, I'm developing an app with Xamarin.Forms 3.3.0.967583 and I'm facing the issue that the camera position is never updated, I have the following code:

XAML:
<maps:Map x:Name="map" VerticalOptions="FillAndExpand"> <maps:Map.Behaviors> <bindings:BindingPinsBehavior Value="{Binding Pins}"/> <bindings:MapClickedToCommandBehavior Command="{Binding MapClickedCommand}"/> <bindings:UpdateCameraPositionBehavior CameraUpdate="{Binding CameraUpdate}" Duration="{Binding Duration}"></bindings:UpdateCameraPositionBehavior> </maps:Map.Behaviors> </maps:Map>

C# View:

` protected override void OnAppearing()
{
base.OnAppearing();
((MapViewModel)BindingContext).Pins.Add(new Pin() { Type = PinType.Place, Label = "Boutique Hotel", Address = "Piłsudskiego 10, 90-368 Łódź, Poland", Position = new Position(51.760082d, 19.461088d), Tag = "tm_hotel" });

        ((MapViewModel)BindingContext).UpdateCameraLocation.Execute(true);
    }

`

C# ViewModel:

`
class MapViewModel : BaseViewModel, INotifyPropertyChanged
{
private bool animated = false;
private double latitude = 0;
private double longitude = 0;

    public ObservableCollection<Pin> Pins { get; set; } = new ObservableCollection<Pin>();

    private CameraUpdate cameraUpdate = null;

    public CameraUpdate CameraUpdate
    {
        get => cameraUpdate;
        set => SetProperty(ref cameraUpdate, value);
    }

    public bool Animated
    {
        get => animated;
        set
        {
            animated = value;
            Duration = animated ? TimeSpan.FromSeconds(2) : (TimeSpan?)null;
        }
    }

    public double Latitude
    {
        get
        {
            return latitude;
        }
        set
        {
            latitude = value;
            OnPropertyChanged(nameof(Latitude));
        }
    }

    public double Longitude
    {
        get
        {
            return longitude;
        }
        set
        {
            longitude = value;
            OnPropertyChanged(nameof(Longitude));
        }
    }

    private TimeSpan? _duration;
    public TimeSpan? Duration
    {
        get => _duration;
        set => SetProperty(ref _duration, value);
    }

    public MapViewModel()
    {
        Title = "Location";
        //                      InitialCameraUpdate="51.760082, 19.461088, 15"
        Latitude = 51.760082d;
        Longitude = 19.461088d;
    }

    public Command<MapClickedEventArgs> MapClickedCommand =>
        new Command<MapClickedEventArgs>(args =>
        {
            Pins.Add(new Pin
            {
                Label = $"Pin{Pins.Count}",
                Position = args.Point
            });
            Latitude = Pins[Pins.Count - 1].Position.Latitude;
            Longitude = Pins[Pins.Count - 1].Position.Longitude;
            UpdateCameraLocation.Execute(true);
        });

    public Command UpdateCameraLocation => new Command(() =>
    {
        CameraUpdate =
            CameraUpdateFactory.NewCameraPosition(
                new CameraPosition(
                    new Position(Latitude, Longitude),
                    15d // zoom
                ));
    });

    #region INotifyPropertyChanged implementation
	#pragma warning disable CS0108 // Member hides inherited member; missing new keyword
    public event PropertyChangedEventHandler PropertyChanged;
	#pragma warning restore CS0108 // Member hides inherited member; missing new keyword

    private new void OnPropertyChanged(string property)
    {
        PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(property));
    }
    #endregion
}

`

Do you have any idea why is not being exposed? Thanks for your support!

The property 'Request' was not found in type 'MoveCameraBehavior'

I'm trying to understand why I'm getting this error.

The property 'Request' was not found in type 'MoveCameraBehavior'

This is my InAutoGuidaPage.xaml code:

<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
             xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
             x:Class="GalileoQuiz.Views.InAutoGuidaPage"
             xmlns:googleMaps="clr-namespace:Xamarin.Forms.GoogleMaps;assembly=Xamarin.Forms.GoogleMaps"
             xmlns:bindings="clr-namespace:Xamarin.Forms.GoogleMaps.Bindings;assembly=Xamarin.Forms.GoogleMaps.Bindings"
             >
    <Grid>
        <googleMaps:Map InitialCameraUpdate="{Binding InitialCameraUpdate}" VerticalOptions="FillAndExpand">
            <googleMaps:Map.Behaviors>
                <bindings:BindingPolylinesBehavior Value="{Binding Polylines}"/>
                <bindings:MoveCameraBehavior Request="{Binding MoveCameraRequest}"/>
            </googleMaps:Map.Behaviors>
        </googleMaps:Map>
    </Grid>
</ContentPage>

I get this error even when I write another binding like this:
<bindings:UpdateCameraPositionBehavior CameraUpdate="{Binding CameraUpdate}" Duration="{Binding Duration}"/>

The property 'CameraUpdate' was not found in type 'UpdateCameraPositionBehavior'

And others like these.

Any suggestions? What am I forgetting?
I'm using Prism Framework with MVVM.

Can't Recognize the Commands in xf 4.1 vs 2019

Keep getting errors on all of the command bindings in the xaml page.
Error XLS0413 The property 'Command' was not found in type 'MapClickedToCommandBehavior'.

xmlns:bindings="clr-namespace:Xamarin.Forms.GoogleMaps.Bindings;assembly=Xamarin.Forms.GoogleMaps.Bindings"
 <googleMaps:Map VerticalOptions="FillAndExpand">
            <googleMaps:Map.Behaviors>
                <bindings:MapClickedToCommandBehavior Command="{Binding MapClickedCommand}" />
                <bindings:BindingPinsBehavior Value="{Binding WindPins}" />
                <bindings:PinClickedToCommandBehavior Command="{Binding PinClickedCommand}" />
                <bindings:SelectedPinChangedToCommandBehavior Command="{Binding SelectedPinChangedCommand}" />
                <bindings:InfoWindowClickedToCommandBehavior Command="{Binding InfoWindowClickedCommand}" />
                <bindings:InfoWindowLongClickedToCommandBehavior Command="{Binding InfoWindowLongClickedCommand}" />
                <bindings:PinDragStartToCommandBehavior Command="{Binding PinDragStartCommand}" />
                <bindings:PinDraggingToCommandBehavior Command="{Binding PinDraggingCommand}" />
                <bindings:PinDragEndToCommandBehavior Command="{Binding PinDragEndCommand}" />
            </googleMaps:Map.Behaviors>
        </googleMaps:Map>

image

Can not move to region upon entering MapPage.

Can not move to region upon entering MapPage.

If I place a button on the screen and use that, it moves just fine... but if I call the method or include the code, it shows the entire map... with the map pin exactly where it is supposed to be.

ICommand centerOnMapPinCommand;
       public ICommand CenterOnMapPinCommand =>
           centerOnMapPinCommand ??
           (centerOnMapPinCommand = new Command(async () => await ExecuteCenterOnMapPinCommand()));

       private async Task ExecuteCenterOnMapPinCommand()
       {
           if (Pins.Count < 1)
           {
               return;
           }

           var currentPosition = Pins[0].Position;

           Request.MoveToRegion(
               MapSpan.FromCenterAndRadius(
                   new Position(currentPosition.Latitude, currentPosition.Longitude),
                   Distance.FromMeters(500)),
               Animated);

       }

Setting default map center

I'm using the googlemaps plugin and the binding plugin - love how easy they are. However, I am confused on how to set an initial camera location other than Rome. In my viewmodel, I create some pins from database and search criteria and then I display the pins on the map. I then have to move the map from Rome to where I think the pins are on the map.

Is there any way to set the initial map "center", "region", etc. to one of the pins from my list of pins so my users don't always have to pan/move from Rome?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.