首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >为什么用户位置不是MKUserLocation?

为什么用户位置不是MKUserLocation?
EN

Stack Overflow用户
提问于 2019-09-27 02:26:04
回答 1查看 89关注 0票数 2

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

下面是我的代码:

代码语言:javascript
复制
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

EN

回答 1

Stack Overflow用户

发布于 2020-06-16 18:13:42

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

代码语言:javascript
复制
    [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;
    }
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/58122722

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档