Skip to content

Conversation

@andreluiz1987
Copy link

Added a new property in TKCustomMapPin.
Creation of the OpenCallout method in the Android and iOS project.

@TorbenK
Copy link
Owner

TorbenK commented May 5, 2017

I'm wondering if this fires PinSelected on iOS? I think it shouldn't. Otherwise I can't see where the difference is to set the SelectedPin, this should also open the callout.

@andreluiz1987
Copy link
Author

For some reason, in this snippet "var annotationView = this.Map.ViewForAnnotation (selectedAnnotation)"
the annotationView is always null and so I can not call the "this.Map.SelectAnnotation (selectedAnnotation, true)".
Really the only difference of the method created is that I do not retrieve the annotationView.

Anyway, it's working here.

@djrpascu
Copy link

djrpascu commented May 22, 2018

This is only affecting iOS.

According to:
https://developer.xamarin.com/api/member/MonoTouch.MapKit.MKMapView.ViewForAnnotation/p/MonoTouch.Foundation.NSObject/

If the annotation's view is not currently visible on the screen, this method will return null.

For me, the callout would display on first try because my map included all of my annotations in the current view. Once I set SelectedPin to one item, it zoomed the view on that one annotation. Next time you try to set SelectedPin to a new pin, in which the annotation is not in the view, it navigates to it, but doesn't select the annotation and returns null. You can test this by simply zooming out on your view to show all annotations, then try the method setting your SelectedPin, the callout displays as expected.

Took a page from @andreluiz1987 example and changed SetSelectedPin() method in TKCustomMapRenderer.cs for iOS.

Changed from:
if (selectedAnnotation != null)
{
var annotationView = GetViewByAnnotation(selectedAnnotation);
_selectedAnnotation = selectedAnnotation;
if (annotationView != null)
{
Map.SelectAnnotation(annotationView.Annotation, true);
}
MapFunctions.RaisePinSelected(FormsMap.SelectedPin);
}

to:

if (selectedAnnotation != null)
{
_selectedAnnotation = selectedAnnotation;
if (selectedAnnotation != null)
{
Map.SelectAnnotation(selectedAnnotation, true);
}
MapFunctions.RaisePinSelected(FormsMap.SelectedPin);
}

You also have to set SelectedPin = null before setting the new pin.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants