C# Xamarin.Forms:Map.IsShowingUser不显示当前位置?
这是我正在开发的应用程序的C# Xamarin.Forms:Map.IsShowingUser不显示当前位置?,c#,android,xamarin,xamarin.forms,visual-studio-2017,C#,Android,Xamarin,Xamarin.forms,Visual Studio 2017,这是我正在开发的应用程序的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-names
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"
xmlns:local="clr-namespace:GasStations"
x:Class="GasStations.MainPage">
<StackLayout>
<StackLayout VerticalOptions="FillAndExpand">
<maps:Map WidthRequest="960" HeightRequest="200"
x:Name="MyMap"
IsShowingUser="true"/>
<ListView x:Name="ListView_Pets">
<ListView.ItemsSource>
<x:Array Type="{x:Type x:String}">
<x:String>dog</x:String>
<x:String>cat</x:String>
<x:String>bird</x:String>
</x:Array>
</ListView.ItemsSource>
</ListView>
</StackLayout>
</StackLayout>
</ContentPage>
狗
猫
鸟
我设置属性Map.IsShowingUser=“true”
,认为它会显示当前位置,但不会显示点
这就是表单的外观。它不显示当前位置pin
我的问题是:如何将当前位置添加到地图
使用获取当前位置。如果尚未安装,然后使用MoveCamera方法移动到该位置:
private async Task TrackCurrentLocation()
{
var current = await CrossGeolocator.Current.GetPositionAsync();
current.Accuracy = 30;
float bearing =//bearing in case any
var pins = new Pin { Label = "ME", Icon =''yourIcon"), Flat = true
};
var latitude = current.Latitude;
var longitude = current.Longitude;
Device.BeginInvokeOnMainThread(() =>
{
pins.Position = new Position(latitude, longitude);
pins.Rotation = bearing;
if (MapTrack.Pins.Count == 0)
{
MapTrack.Pins.Add(pins);
}
else
{
MapTrack.Pins[0] = pins;
}
MapTrack.MoveCamera(CameraUpdateFactory.NewPosition(new Position(latitude, longitude)));
});
}
触摸“我的位置”按钮(右上角)