我Xamarin.forms.Maps
用来在我的项目中显示地图。该地图位于列表视图中,我需要将坐标位置绑定到该地图。
我的代码:
型号类别:
public class History
{
public double Latitude { get; set; }
public double Longitude { get; set; }
}
数据添加部分:
historyList.Add(new History() { Latitude= -28.854930 ,Longitude= 151.166023 });
historyList.Add(new History() { Latitude = -28.853671, Longitude = 151.165712 });
historyList.Add(new History() { Latitude = -28.853934, Longitude = 151.167118 });
historyList.Add(new History() { Latitude = -28.855178, Longitude = 151.167946 });
historylistview.ItemsSource = historyList;
XAML
<ListView x:Name="historylistview">
<ListView.ItemTemplate>
<DataTemplate>
<ViewCell>
<ViewCell.View>
<StackLayout
HorizontalOptions="Center">
<maps:Map
x:Name="maps"
VerticalOptions="Center"
HorizontalOptions="Center">
<x:Arguments>
<maps:MapSpan>
<x:Arguments>
<maps:Position>
<x:Arguments>
<x:Double>{Binding Latitude}</x:Double>
<x:Double>{Binding Longitude}</x:Double>
</x:Arguments>
</maps:Position>
<x:Double>0.01</x:Double>
<x:Double>0.01</x:Double>
</x:Arguments>
</maps:MapSpan>
</x:Arguments>
</maps:Map>
</StackLayout>
</ViewCell.View>
</ViewCell>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
该地图显示在每一行中,但位置值错误。我已经从得克萨斯州给出了位置,但地图显示了在Nijerya的某个地方。
是否可以对类型进行绑定x:Arguments
?
MapSpan和Map中的Position是不可绑定的属性,因此,如果您使用数据绑定,它将永远无法工作。
如果要显示职位列表
<ListView x:Name="historylistview">
<ListView.ItemTemplate>
<DataTemplate>
<ViewCell>
<ViewCell.View>
<StackLayout
HorizontalOptions="Center">
<maps:Map x:Name="map"
ItemsSource="{Binding positionList}">
<maps:Map.ItemTemplate>
<DataTemplate>
<maps:Pin Position="{Binding .}"/>
</DataTemplate>
</maps:Map.ItemTemplate>
</maps:Map>
</StackLayout>
</ViewCell.View>
</ViewCell>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
historyList.Add(new History() { positionList = new ObservableCollection<Position>() { new Position(36.9628066, -122.0194722) },xxx="title here" });
historyList.Add(new History() { positionList = new ObservableCollection<Position>() { new Position(36.9628066, -122.0194722) }, xxx = "title here" });
//...
historylistview.ItemsSource = historyList;
public class History
{
public ObservableCollection<Position> positionList { get; set; }
//other property
public string xxx { get; set; }
}
检查文档以获取更多详细信息
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句