简体   繁体   English

如何更新 xamarin forms 映射中的引脚?

[英]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.

相关问题 如何使用 xamarin.forms.maps android 将数据库中的数据添加到引脚 - How to add data from database into pins using xamarin.forms.maps android Xamarin.Forms.Maps 我如何像出租车一样旋转销钉 - Xamarin.Forms.Maps How i can rotation pins like a taxi 如何在当前位置附近加载引脚并在缩小 Xamarin.Forms.Maps 时加载更多 - How to load pins just around your current location and load more as you zoom out in Xamarin.Forms.Maps 谷歌地图绑定 Xamarin.Forms - 使用 BindingPinsBehavior 时,引脚未显示在 map 上 - Google Maps Bindings Xamarin.Forms - Pins not showing on map when using BindingPinsBehavior Xamarin Forms Maps Android - Xamarin Forms Maps Android 如何使用 Xamarin.Forms.Maps 在 iOS 上使用 Google 地图? - How to use Google Maps on iOS using Xamarin.Forms.Maps? 如何在 Xamarin.Forms 中使用 Xamarin.GooglePlayServices.Maps? - How use a Xamarin.GooglePlayServices.Maps in Xamarin.Forms? 如何以xamarin形式查看两个引脚之间的距离并将距离作为一个字符串? - How can I see distance between two pins in xamarin forms and get the distance as a string? 如何使用 Xamarin 表单中的 SQLite 更新数据库中的项目 - How to update an item in database with SQLite in Xamarin forms Xamarin 谷歌地图绑定:BindingPinsBehavior 未显示 map 上的引脚 - Xamarin google maps bindings:BindingPinsBehavior not showing Pins on map
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM