[英]How to update pins in xamarin forms maps?
I have the following code:我有以下代码:
private async void setHelpersPins(object sender, ElapsedEventArgs e)
{
var temp = await firebaseHelper.GetAllHelperUsers();
if (map.Pins.Count>0)
{
map.Pins.Clear();
}
foreach (var user in temp)
{
Pin pin = new Pin
{
Label = user.Nickname,
Address = "További információkért kattints ide.",
Type = PinType.Place,
Position = new Position(user.Latitude, user.Longitude)
};
map.Pins.Add(pin);
}
}
It runs every 10second by using Timer.Elapsed
.它使用
Timer.Elapsed
每 10 秒运行一次。
But it makes the map blinks every time this method runs, which is not great for me.但它使 map 每次运行此方法时都会闪烁,这对我来说不是很好。
How can I only update those pin coordinates, where the user's nicknames are the same?我怎样才能只更新那些用户昵称相同的引脚坐标?
to find the elements of a collection, use a LINQ query要查找集合的元素,请使用 LINQ 查询
using System.Linq;
....
var pins = map.Pins.Where(x => x.Label == "somevalue").ToList();
then you can iterate over the list to update it然后你可以遍历列表来更新它
foreach (var p in pins)
{
p.Position = someNewPosition;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.