只有一个注释--用户位置。我没有添加任何其他的。
下面是我的代码:
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
发布于 2020-06-16 18:13:42
你需要引用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;
}https://stackoverflow.com/questions/58122722
复制相似问题