Kia ora StackOverFlow,
I'm creating a Google Maps page which has numerous bindings (I used Google Maps bindings). An example of this bindings is a pin bindings - as you will see below:
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:maps="clr-namespace:Xamarin.Forms.GoogleMaps;assembly=Xamarin.Forms.GoogleMaps"
xmlns:bindings="clr-namespace:Xamarin.Forms.GoogleMaps.Bindings;assembly=Xamarin.Forms.GoogleMaps.Bindings"
x:Class="standard.MainPage">
<StackLayout>
<maps:Map VerticalOptions="FillAndExpand"
MyLocationEnabled="True">
<maps:Map.Behaviors>
<bindings:BindingPinsBehavior Value="{Binding Pins}" />
</maps:Map.Behaviors>
</maps:Map>
</StackLayout>
</ContentPage>
ViewModel:
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Text;
using System.Threading.Tasks;
using Xamarin.Forms.GoogleMaps;
using Xamarin.Forms.GoogleMaps.Bindings;
namespace standard.ViewModels
{
public class MainPageViewModel : BaseViewModel
{
private ObservableCollection<Pin> _pins;
public ObservableCollection<Pin> Pins
{
get => _pins;
set
{
_pins = value;
RaisePropertyChanged();
}
}
public MainPageViewModel()
{
Pins = new ObservableCollection<Pin>();
Pins.Add(new Pin()
{
Type = PinType.Place,
Position = new Position(78,77)
});
}
}
}
Xaml.CS:
using standard.ViewModels;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Xamarin.Forms;
using Xamarin.Forms.GoogleMaps;
namespace standard
{
public partial class MainPage : ContentPage
{
public MainPageViewModel MainPageViewModel;
public MainPage()
{
InitializeComponent();
this.BindingContext = MainPageViewModel = new MainPageViewModel();
}
}
Now - the problem is - I've set the BindingContext as expected but the pin is NOWHERE to be seen on the map.
It's important that I can see the pins on the map because I am making an app in which the user needs to see the location of the event/party. I also want a solution in an MVVM approach.
(using Android lollipop)
image
Thank you,
Kia pai to ra
Have a great day
Edit: Thank you to Leo Zhu who kind of solved my question - I am looking for an MVVM-based solution for now but thank you anyways
Things I've tried | Result |
---|---|
Tried to set the Binding of the pins using the default maps item template. | Still did not work or show on the map |
Tried to call OnPropertyChanged after adding an item to the observable collection | Still the pin did not show on the map |
Tried using a Pin instead of an ObservableCollections of Pins | Still the Pin was nowhere to be seen on the map |
Tried setting the BindingContext of the map itself to the MainPageViewModel | Still the Pin is nowhere to be seen |
Tried to use an earlier update of the Google Maps Binding NuGet package | Still - you guessed it - I cannot see the pin |