System.NullReferenceException Xamarin Maps

时间:2016-10-19 22:20:16

标签: xamarin xamarin.forms

我在显示地图时遇到NullException但无法检测到; 我试图改变地图,locazation等的名称,但没有成功。 你或许可以找出我的错误,请帮助我!

    public partial class LocationPage : ContentPage
    {
        public Clinica _clinica;

        public LocationPage(Clinica clinica)
        {
            InitializeComponent();
            Clinica = clinica;
            SetupMap();
        }



        public Clinica Clinica
        {
            get
            {
                return _clinica;
            }

            set
            {
                _clinica = value;
            }
        }

        protected override void OnAppearing()
        {
            base.OnAppearing();

            // Typically, is preferable to call into the viewmodel for OnAppearing() logic to be performed,
            // but we're not doing that in this case because we need to interact with the Xamarin.Forms.Map property on this Page.
            // In the future, the Map type and it's properties may get more binding support, so that the map setup can be omitted from code-behind.
            SetupMap();
        }

        void SetupMap()
        {
            if (Device.OS != TargetPlatform.WinPhone && Device.OS != TargetPlatform.Windows)
            {
                var pin = new Pin()
                {
                    Type = PinType.Place,
                    Position = new Position(Clinica.Latitude, Clinica.Longitude),
                    Label = Clinica.Nome

                };

                clinicaMap.Pins.Clear();

                clinicaMap.Pins.Add(pin);

                clinicaMap.MoveToRegion(MapSpan.FromCenterAndRadius(pin.Position, Distance.FromMiles(10)));
            }
        }
    }
}

LocationPage.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.Maps;assembly=Xamarin.Forms.Maps"
             x:Class="CartaoDeTodos.View.LocationPage">
    <StackLayout>
        <maps:Map x:Name="clinicaMap"
                        VerticalOptions="FillAndExpand"/>
    </StackLayout>
</ContentPage>

Erro

enter image description here

enter image description here

0 个答案:

没有答案