比较坐标时,它们不相等并且不在地图上显示图钉 - xamarin.forms.maps

When comparing coordinates they are not equal and not displaying pins on the map - xamarin.forms.maps

我在 class 中有 1919 个坐标:

public class HardcodedLocations
{
    public static List<Position> Positions = new List<Position>
    {
           new Position(41.19197,   25.33719 ),
           new Position(41.26352,   25.1471 ),
           new Position(41.26365,   25.24215 ),
           new Position(41.26369,   25.33719 ),
     }
}

我在构造函数页面添加坐标:

public AboutPage()
    {
        InitializeComponent();

        List<CustomPin> pins = new List<CustomPin>();

        for (int i = 0; i < HardcodedLocations.Positions.Count; i++)
        {
            CustomPin pin = new CustomPin
            {
                Type = PinType.Place,
                Position = HardcodedLocations.Positions[i],
                Label = "Xamarin San Francisco Office",
                Address = "394 Pacific Ave, San Francisco CA",
                Name = "Xamarin",
                Url = "http://xamarin.com/about/"
            };

            pins.Add(pin);
            customMap.Pins.Add(pin);
            customMap.MoveToRegion(MapSpan.FromCenterAndRadius(new Position(42.8742, 25.3187), Distance.FromMiles(1.0)));
        }
        customMap.CustomPins = pins;

但是标记没有显示,因为在这个方法中它们不等于:

 CustomPin GetCustomPin(MKPointAnnotation annotation)
    {

        var position = new Position(annotation.Coordinate.Latitude, annotation.Coordinate.Longitude);

        foreach (var pin in customPins)
        {
            if (pin.Position.Latitude == position.Latitude && pin.Position.Longitude == position.Longitude)
            {
                return pin;
            }
        }
        return null;
    }

当我在第一次迭代中的 if 语句上停止调试器时 pin.Position.LatitudeList<Position>HardcodedLocations class 和 position.Latitude 得到 0 索引1083指数。 pin.Position.Longitude 等于 position.Longitude.

在第二次迭代中 pin.Position.LatitudeList<Position>HardcodedLocations class 得到 1 个索引,position.Latitude 再次得到 1083 个索引。 pin.Position.Longitude 获得 1 个索引 position.Longitude 获得不同的索引。

出现差异的原因是什么?我该如何解决这个问题?

尝试直接比较两个位置,如示例所示

CustomPin GetCustomPin(MKPointAnnotation annotation)
{
   var position = new Position(annotation.Coordinate.Latitude, annotation.Coordinate.Longitude);
   foreach (var pin in customPins)
   {
       if (pin.Position == position)
       {
           return pin;
       }
   }
   return null;
}

此处示例:https://github.com/xamarin/xamarin-forms-samples/blob/dacfaec98cf6ddfa587a80a9d9338c14cfb123d1/CustomRenderers/Map/iOS/CustomMapRenderer.cs#L111 .