【问题标题】:Why is User Location not MKUserLocation?为什么用户位置不是 MKUserLocation?
【发布时间】:2019-09-26 18:26:03
【问题描述】:

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

这是我的代码:

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

【问题讨论】:

  • 阅读此comment 可能会有所帮助。

标签: ios xamarin xamarin.ios


【解决方案1】:

您需要参考 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;
    }

【讨论】:

    猜你喜欢
    • 2014-11-16
    • 2012-11-29
    • 2015-10-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-06-29
    • 2021-10-21
    • 2019-10-23
    相关资源
    最近更新 更多