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)
What Im looking is "Bounds" property, but that I only found on XF.GoogleMaps which nuget I dont use.
for Android in my custom renderer I pout LatLngBounds class and made a builder, thats works just fine, but on iOS I didnt find a solution.
Thanks
UPDATE #1: Is this a right method in iOS renderer to put ShowAnnotations? And how to re-pack it to MkAnnotation from Pin model?
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;
}
}
You are looking for the ShowAnnotations
on your MKMapView
.
You pass in the array of pins ( annotations
) that you wish the map to center and zoom to to able all those pins to the shows at the same time:
yourMapView.ShowAnnotations (new [] { pin }, false);
Apple Docs: showAnnotations:animated:
Xamarin Docs: ShowAnnotations
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.