0

Xamarin Forms Mapsui コントロールにピンを追加しようとしています。

これが私のXamlです

<mapsui:MapView x:Name="selectMapControl"
        VerticalOptions="FillAndExpand"
        HorizontalOptions="Fill"
        BackgroundColor="Gray" />

これが私のコードです:

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

            var map = new Map
            {
                CRS = "EPSG:3857",
                Transformation = new MinimalTransformation()
            };

            var tileLayer = OpenStreetMap.CreateTileLayer();

            map.Layers.Add(tileLayer);
            map.Widgets.Add(new Mapsui.Widgets.ScaleBar.ScaleBarWidget(map) { TextAlignment = Mapsui.Widgets.Alignment.Center, HorizontalAlignment = Mapsui.Widgets.HorizontalAlignment.Left, VerticalAlignment = Mapsui.Widgets.VerticalAlignment.Bottom });

            selectMapControl.Map = map;

            double lat = 36.9628066;
            double lng = -122.0194722;

            var myPosition = new Position(lat, lng);
            var myPin = new Pin(selectMapControl) //Exception here
            {
               Position = myPosition,
               Type = PinType.Pin,
               Label = "Zero point",
               Address = "Zero point",
            };
            selectMapControl.Pins.Add(myPin);
}

var myPin = new Pin(selectMapControl)...行で「オブジェクト参照がオブジェクトのインスタンスに設定されていません。」という例外が発生します。

私の緯度と経度が両方とも 0 に設定されている場合、それは機能します。例外のスタック トレースは次のとおりです。

   at Mapsui.UI.Forms.Pin.OnPropertyChanged (System.String propertyName) [0x001df] in <5cc65edf513349cdba641e049bbf0143>:0 

Xamarin.Forms.BindableObject.SetValueActual (Xamarin.Forms.BindableProperty プロパティ、Xamarin.Forms.BindableObject+BindablePropertyContext コンテキスト、System.Object 値、System.Boolean currentlyApplying、Xamarin.Forms.Internals.SetValueFlags 属性、System.Boolean サイレント) [ D:\a\1\s\Xamarin.Forms.Core\BindableObject.cs:510 の Xamarin.Forms.BindableObject.SetValueCore (Xamarin.Forms.BindableProperty プロパティ、System.Object 値、Xamarin.Forms.Internals. SetValueFlags 属性、Xamarin.Forms.BindableObject+SetValuePrivateFlags privateAttributes) [0x00173] D:\a\1\s\Xamarin.Forms.Core\BindableObject.cs:446 at Xamarin.Forms.BindableObject.SetValue (Xamarin.Forms.BindableProperty)プロパティ、System.Object 値、System.Boolean fromStyle、System.Boolean checkAccess) [0x0004d] D:\a\1\s\Xamarin.Forms.Core\BindableObject.cs:374 at Xamarin.Forms.BindableObject.SetValue (Xamarin.Forms.BindableProperty プロパティ、System.Object 値) [0x00000] D:\a\1\s\Xamarin.Forms.Core\BindableObject.cs:349 at Mapsui.UI .Forms.Pin.set_Position (Mapsui.UI.Forms.Position 値) [0x00000] in <5cc65edf513349cdba641e049bbf0143>:0 at eLunaApp.Views.RestaurantMapPage.OnAppearing () [0x0008d] in C:\x\elunaapp\eLunaApp\PageRestaurantMap\ RestaurantMapPage.xaml.cs:82 at Xamarin.Forms.Page.SendAppearing () [0x00045] D:\a\1\s\Xamarin.Forms.Core\Page.cs:452 at Xamarin.Forms.ShellContent.SendPageAppearing ( Xamarin.Forms.Page ページ) [0x0003b] in D:\a\1\s\Xamarin.Forms.Core\Shell\ShellContent.cs:127 at Xamarin.Forms.ShellContent.SendAppearing () [0x00019] in D:\ a\1\s\Xamarin.Forms.Core\Shell\ShellContent.cs:108 at Xamarin.Forms.ShellContent.OnChildAdded (Xamarin.Forms.Element child) [0x00021] in D:\a\1\s\Xamarin.Forms.Core\Shell\ShellContent.cs:138 at Xamarin.Forms.ShellContent.set_ContentCache (Xamarin.Forms.Page value) [0x0003b] in D :\a\1\s\Xamarin.Forms.Core\Shell\ShellContent.cs:182 at Xamarin.Forms.ShellContent.Xamarin.Forms.IShellContentController.GetOrCreateContent () [0x0003c] in D:\a\1\s\ Xamarin.Forms.Core\Shell\ShellContent.cs:68 at Xamarin.Forms.Platform.Android.ShellSectionRenderer.OnCreateView (Android.Views.LayoutInflater インフレータ、Android.Views.ViewGroup コンテナー、Android.OS.Bundle savedInstanceState) [0x000f2] D:\a\1\s\Xamarin.Forms.Platform.Android\Renderers\ShellSectionRenderer.cs:166 で AndroidX.Fragment.App.Fragment.n_OnCreateView_Landroid_view_LayoutInflater_Landroid_view_ViewGroup_Landroid_os_Bundle_ (System.IntPtr jnienv、System.IntPtr native__this、System.IntPtr native_inflater 、System.IntPtr native_container, System.IntPtr native_savedInstanceState) [0x00021] in D:\a\1\s\generated\androidx.fragment.fragment\obj\Release\monoandroid90\generated\src\AndroidX.Fragment.App.Fragment.cs :1950 at (wrapper dynamic-method) Android.Runtime.DynamicMethodNameCounter.50(intptr,intptr,intptr,intptr,intptr)

4

0 に答える 0