只有一个注释-用户位置。我没有添加任何其他内容。

这是我的代码:

public override MKAnnotationView GetViewForAnnotation(MKMapView mapView, IMKAnnotation annotation)
{
    if (annotation is MKUserLocation)
    {
        return null;//never hit
    }
    else if (annotation is myAnnotation  a)
    {
        return a.View;//never hit of course.
    }
    else
    {
        string vvvvvvv = annotation.GetType().ToString();//"MKAnnotationWrapper"
        return null;//hit even though I didn't add anything else.
    }
}

为什么用户位置显示为MKAnnotationWrapper而不显示为MKUserLocation

最佳答案

您需要引用OBJC运行时对象,然后可以检查它,例如:

    [Export("mapView:viewForAnnotation:")]
    public MKAnnotationView GetViewForAnnotation(MKMapView mapView, IMKAnnotation annotation)
    {
        //pass pointer to GetNSObject and cast it to MKUserLocation then you
        //can know if it is user location or not
        var userAnnotation = Runtime.GetNSObject(annotation.Handle) as MKUserLocation;
        if (userAnnotation != null)
        {
            return null;//when returning null there will be default pin for user
        }
        var annView = new MKAnnotationView//custom annotation logic
           {
               Image = pinImage,
               CanShowCallout = false,
               Annotation = annotation,
            };
        return annView;
    }

关于ios - 为什么用户位置不是MKUserLocation?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/58122722/

10-11 17:15