0

我正在使用 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>某种方式创建一个?

4

1 回答 1

0

您没有为每个创建一个 pin getItems,只为最后一个创建一个 pin,尝试扩展 forforeach以包装整个代码片段:

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. 
    }
}
于 2016-01-26T23:42:48.130 回答