我正在使用xamarin表单中的地图,并遇到了一个我似乎无法解决的问题。 我想添加多个引脚(到多个位置),在我的数据库中解析我有3个不同位置的数据但是当我在应用程序上测试它时,地图上只显示1个引脚。
这是我的代码:
var getItems = await parseAPI.getInfo (Application.Current.Properties ["sessionToken"].ToString ()); //I load my data.
foreach (var currentItem in getItems["results"]) {
mLong = currentItem ["long"].ToString (); //my long from my data
mLat = currentItem ["lat"].ToString (); //my lat from my data
}
var storeLong = Double.Parse (mLong, CultureInfo.InvariantCulture); //converting the long from string to int.
var storeLat = Double.Parse (mLat, CultureInfo.InvariantCulture); //converting the lat from string to int.
if (mLong != null) {
var pin = new Pin ();
pin.Position = new Position (storeLat,storeLng); //here i add the data i have.
pin.Label = "test";
pin.Address = "test";
theMap.Pins.Add (pin); //adding my pins to my map.
}
也许我需要以某种方式创建list <String>
?
答案 0 :(得分:0)
您没有为每个getItems
创建一个引脚,只为最后一个创建一个引脚,尝试扩展foreach
以包装整个代码段:
var getItems = await parseAPI.getInfo (Application.Current.Properties ["sessionToken"].ToString ()); //I load my data.
foreach (var currentItem in getItems["results"])
{
mLong = currentItem ["long"].ToString (); //my long from my data
mLat = currentItem ["lat"].ToString (); //my lat from my data
var storeLong = Double.Parse (mLong, CultureInfo.InvariantCulture); //converting the long from string to int.
var storeLat = Double.Parse (mLat, CultureInfo.InvariantCulture); //converting the lat from string to int.
if (mLong != null)
{
var ourPosition = new Position (13, -15);
theMap.MapType = MapType.Hybrid;
theMap.MoveToRegion (
MapSpan.FromCenterAndRadius (
ourPosition, Distance.FromMeters (300)));
var pin = new Pin ();
pin.Position = new Position (storeLat,storeLng); //here i add the data i have.
pin.Label = "test";
pin.Address = "test";
pin.Clicked += onButtonClicked1;
theMap.Pins.Add (pin); //adding my pins to my map.
}
}