使用 Xamarin.Forms.Map 未显示标签和图钉
Label and pins not showing using Xamarin.Forms.Map
VS 2019 所有更新。
我使用 nuget 安装 Xamarin.Forms.Map。
使用 Xamarin Android 显示带定位点的地图。
前端XAML是
<ContentPage.Content>
<maps:Map x:Name="Map"/>
</ContentPage.Content>
在代码隐藏中我有
public TestPage()
{
InitializeComponent();
var map = new Map(MapSpan.FromCenterAndRadius(new Position(37, -122), Distance.FromMiles(10)));
var pin = new Pin()
{
Position = new Position(37, -122),
Label = "Some Pin!"
};
map.Pins.Add(pin);
var cp = new ContentPage
{
Content = map,
};
}
我从 MSDN https://docs.microsoft.com/en-us/dotnet/api/xamarin.forms.maps.map?view=xamarin-forms.
关注的
然后我单击 pixel_2_pie_api_28 (F5),页面加载后它会显示地图,但不会显示我设置的位置(我随机更改了位置值)或针点甚至标签?我错过了什么?
你的代码有不少问题
// you already have a map declared in your XAML, you do not need to do it again
var map = new Map(MapSpan.FromCenterAndRadius(new Position(37, -122), Distance.FromMiles(10)));
var pin = new Pin()
{
Position = new Position(37, -122),
Label = "Some Pin!"
};
// add this to your existing XAML map, which you named "Map"
Map.Pins.Add(pin);
// you already have a ContentPage, you don't need to declare a new one
var cp = new ContentPage
{
Content = map,
};
所有你需要做的
var pin = new Pin()
{
Position = new Position(37, -122),
Label = "Some Pin!"
};
Map.Pins.Add(pin);
将地图移动到特定位置
var span = MapSpan.FromCenterAndRadius(new Position(37, -122), Distance.FromMiles(10));
Map.MoveToRegion(span);
VS 2019 所有更新。 我使用 nuget 安装 Xamarin.Forms.Map。
使用 Xamarin Android 显示带定位点的地图。
前端XAML是
<ContentPage.Content>
<maps:Map x:Name="Map"/>
</ContentPage.Content>
在代码隐藏中我有
public TestPage()
{
InitializeComponent();
var map = new Map(MapSpan.FromCenterAndRadius(new Position(37, -122), Distance.FromMiles(10)));
var pin = new Pin()
{
Position = new Position(37, -122),
Label = "Some Pin!"
};
map.Pins.Add(pin);
var cp = new ContentPage
{
Content = map,
};
}
我从 MSDN https://docs.microsoft.com/en-us/dotnet/api/xamarin.forms.maps.map?view=xamarin-forms.
关注的然后我单击 pixel_2_pie_api_28 (F5),页面加载后它会显示地图,但不会显示我设置的位置(我随机更改了位置值)或针点甚至标签?我错过了什么?
你的代码有不少问题
// you already have a map declared in your XAML, you do not need to do it again
var map = new Map(MapSpan.FromCenterAndRadius(new Position(37, -122), Distance.FromMiles(10)));
var pin = new Pin()
{
Position = new Position(37, -122),
Label = "Some Pin!"
};
// add this to your existing XAML map, which you named "Map"
Map.Pins.Add(pin);
// you already have a ContentPage, you don't need to declare a new one
var cp = new ContentPage
{
Content = map,
};
所有你需要做的
var pin = new Pin()
{
Position = new Position(37, -122),
Label = "Some Pin!"
};
Map.Pins.Add(pin);
将地图移动到特定位置
var span = MapSpan.FromCenterAndRadius(new Position(37, -122), Distance.FromMiles(10));
Map.MoveToRegion(span);