【发布时间】:2022-06-13 11:50:58
【问题描述】:
如何将 pin 标记添加到图像并在 xamarin.forms 中获取此标记的当前位置
【问题讨论】:
-
正如写的这个问题没有任何意义。请edit 它包含有关您要完成的工作的更多有用细节。添加您尝试构建的 UI 模型可能会有所帮助。请阅读How to Ask 以获取有关编写主题问题的更多指导
标签: xamarin.forms
如何将 pin 标记添加到图像并在 xamarin.forms 中获取此标记的当前位置
【问题讨论】:
标签: xamarin.forms
您可以使用custom renders 自定义每个平台中的引脚,例如:
IOS:
protected override MKAnnotationView GetViewForAnnotation(MKMapView mapView, IMKAnnotation annotation)
{
MKAnnotationView annotationView = null;
if (annotation is MKUserLocation)
return null;
var customPin = GetCustomPin(annotation as MKPointAnnotation);
if (customPin == null)
{
throw new Exception("Custom pin not found");
}
annotationView = mapView.DequeueReusableAnnotation(customPin.Name);
if (annotationView == null)
{
annotationView = new CustomMKAnnotationView(annotation, customPin.Name);
annotationView.Image = UIImage.FromFile("pin.png");
annotationView.CalloutOffset = new CGPoint(0, 0);
annotationView.LeftCalloutAccessoryView = new UIImageView(UIImage.FromFile("monkey.png"));
annotationView.RightCalloutAccessoryView = UIButton.FromType(UIButtonType.DetailDisclosure);
((CustomMKAnnotationView)annotationView).Name = customPin.Name;
((CustomMKAnnotationView)annotationView).Url = customPin.Url;
}
annotationView.CanShowCallout = true;
return annotationView;
}
安卓:
protected override MarkerOptions CreateMarker(Pin pin)
{
var marker = new MarkerOptions();
marker.SetPosition(new LatLng(pin.Position.Latitude, pin.Position.Longitude));
marker.SetTitle(pin.Label);
marker.SetSnippet(pin.Address);
marker.SetIcon(BitmapDescriptorFactory.FromResource(Resource.Drawable.pin));
return marker;
}
【讨论】: