[英]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.