我对Xamarin和MvvmCross很新。我正在尝试创建一个示例应用程序,但我被卡住了。我想要做的是从ViewModel访问我的可观察集合到我的视图中。我正在使用Geocodes填充我的ViewModel中的列表,我将其作为API响应获取,并且我想在我的视图中访问这些地理编码,以便我可以在Google地图上制作标记。有没有办法做到这一点。
这里我将响应添加到我的可观察集合中。
FirstViewModel.cs
var item = response["Response"]["SearchResults"]["Location"];
if (item.Type == JTokenType.Array)
{
JArray lst= (JArray)list;
Length = lst.Count;
for (int i = 0; i < Length; i++)
{
ResultLists.Add(new ResultList
{
Latitude = (string)response["Response"]["SearchResults"]["Location"][i]["Geocode"]["Latitude"],
Longitude = (string)response["Response"]["SearchResults"]["Location"][i]["Geocode"]["Longitude"]
});
}
}
在我看来,我希望能够将我保存在我的收藏中的那些地理编码用于在地图上制作标记。
FirstFragment.cs
public void OnMapReady(GoogleMap googleMap)
{
_map = googleMap;
//I am trying to access that list of Geocodes here to make markers on my map
//LatLng marker = new LatLng(ViewModel.Lat, ViewModel.Lng);
//Console.WriteLine("Google Map Marker Location: " + marker);
//googleMap.MoveCamera(CameraUpdateFactory.NewLatLngZoom(VimyRidge, 13));
//googleMap.AddMarker(new MarkerOptions().SetTitle("This is VimyRidge!").SetPosition(VimyRidge));
}