[英]Xamarin Forms Maps iOS bounds - show all pins on the screen
Im using Xamarin Forms Maps, and I want to have the same feature on iOS as I have on Android devices - show all pins on the screen (appropriate position and zoom)
我正在寻找的是“Bounds”属性,但我只在 XF.GoogleMaps 上找到了我不使用的 nuget。
对于 Android 在我的自定义渲染器中我撅嘴 LatLngBounds class 并制作了一个构建器,这很好用,但是在 iOS 上我没有找到解决方案。
谢谢
更新 #1:这是 iOS 渲染器中放置 ShowAnnotations 的正确方法吗? 以及如何将其从引脚 model 重新打包到 MkAnnotation?
protected override void OnElementChanged(ElementChangedEventArgs<View> e)
{
base.OnElementChanged(e);
if (e.OldElement != null)
{
var nativeMap = Control as MKMapView;
nativeMap.GetViewForAnnotation = null;
nativeMap.ZoomEnabled = true;
nativeMap.CalloutAccessoryControlTapped -= OnCalloutAccessoryControlTapped;
nativeMap.DidSelectAnnotationView -= OnDidSelectAnnotationView;
nativeMap.DidDeselectAnnotationView -= OnDidDeselectAnnotationView;
}
if (e.NewElement != null)
{
var formsMap = (CustomMap)e.NewElement;
var nativeMap = Control as MKMapView;
customPins = formsMap.CustomPins;
//MKAnnotation an = formsMap.CustomPins;
var numberOfPins = formsMap.CustomPins.Count;
MKAnnotation[] anotationArray = new MKAnnotation[numberOfPins];
for (int i = 0; i < numberOfPins; i++)
{
anotationArray[0].Coordinate = customPins.ElementAt(0).Position...
}
foreach (var pin in formsMap.CustomPins)
{
}
nativeMap.ZoomEnabled = true;
nativeMap.GetViewForAnnotation = GetViewForAnnotation;
nativeMap.CalloutAccessoryControlTapped += OnCalloutAccessoryControlTapped;
nativeMap.DidSelectAnnotationView += OnDidSelectAnnotationView;
nativeMap.DidDeselectAnnotationView += OnDidDeselectAnnotationView;
}
}
您正在寻找MKMapView
上的ShowAnnotations
。
您传入您希望 map 居中并缩放以使所有这些引脚能够同时显示的引脚数组( annotations
):
yourMapView.ShowAnnotations (new [] { pin }, false);
苹果文档: showAnnotations:animated:
Xamarin 文档: ShowAnnotations
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.