当我从我的数据库加载数据时,我想在我的地图上创建多个图钉,现在我只得到 1 个图钉
When I load data from my database I want to create multiple pins on my map, now I only get 1 pin
我正在使用 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>
?
您没有为每个 getItems
创建一个 pin,只有最后一个,尝试扩展 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.
}
}
我正在使用 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>
?
您没有为每个 getItems
创建一个 pin,只有最后一个,尝试扩展 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.
}
}