每当我通过右侧标注附件按钮点击注释视图时,我获得该点的纬度和经度,工作正常,但有时候显示另一个针脚纬度和经度。
为什么会这样?
MKAnnotationView GetViewForAnnotation (MKMapView mapView, NSObject annotation)
{
if (annotation is MKUserLocation)
return null;
// handle our two custom annotations
if (imgHazardType==1)
{
const string PoliceAnnotationIdentifier = "PoliceAnnotationIdentifier";
MKAnnotationView pinView = (MKAnnotationView)mapView.DequeueReusableAnnotation (PoliceAnnotationIdentifier);
if (pinView == null)
{
MKAnnotationView policeannotationView = new MKAnnotationView (annotation, PoliceAnnotationIdentifier);
policeannotationView.CanShowCallout = true;
UIImage flagImage = UIImage.FromFile ("Images/cop-point.png");
UIButton infobutton =UIButton.FromType(UIButtonType.DetailDisclosure);
policeannotationView.RightCalloutAccessoryView= infobutton;
infobutton.TouchUpInside+= (sender, e) =>
{
NSUserDefaults.StandardUserDefaults.SetString((annotation as Annotation).Coordinate.Latitude.ToString (),"lat");
NSUserDefaults.StandardUserDefaults.SetString((annotation as Annotation).Coordinate.Longitude.ToString (),"lon");
} ;
RectangleF resizeRect;
resizeRect.Size = flagImage.Size;
SizeF maxSize = View.Bounds.Inset (AnnotationPadding, AnnotationPadding).Size;
maxSize.Height -= NavigationController.NavigationBar.Frame.Size.Height - CalloutHeight;
if (resizeRect.Size.Width > maxSize.Width)
resizeRect.Size = new SizeF (maxSize.Width, resizeRect.Size.Height / resizeRect.Size.Width * maxSize.Width);
if (resizeRect.Size.Height > maxSize.Height)
resizeRect.Size = new SizeF (resizeRect.Size.Width / resizeRect.Size.Height * maxSize.Height, maxSize.Height);
resizeRect.Location = PointF.Empty;
UIGraphics.BeginImageContext (resizeRect.Size);
flagImage.Draw (resizeRect);
UIImage resizedImage = UIGraphics.GetImageFromCurrentImageContext ();
UIGraphics.EndImageContext ();
policeannotationView.Image = resizedImage;
policeannotationView.Opaque = false;
pinViews.Add (policeannotationView);
return policeannotationView;
}
else
{
pinView.Annotation = annotation;
}
return pinView;
}
return null;
}