[iOS]Error in AddAnnotation method of CustomPin in MauiMaps Sample
HobDev opened this issue · 6 comments
Error CS1061 'CustomPin' does not contain a definition for 'AddAnnotation' and no accessible extension method 'AddAnnotation' accepting a first argument of type 'CustomPin' could be found (are you missing a using directive or an assembly reference?)
The repro project:
https://github.com/HobDev/CustomPinSample
You didn't add this class: https://github.com/VladislavAntonyuk/MauiSamples/blob/main/MauiMaps/Platforms/iOS/MapExtensions.cs
The mentioned class is here: https://github.com/HobDev/CustomPinSample/blob/master/CustomizedMap/Platforms/iOS/MapExtensions.cs
But AddAnnotation() is method in MapExtensions class. How it can be called by control.AddAnnotation() as control is type of CustomPin.
the problem is in your namespace. you should either add
#if IOS
using CustomizedMap.Platforms.iOS
#endif
or change the namespace to CustomizedMap.CustomControl
@VladislavAntonyuk Thank you ! the issue is resolved by adding the namespace in iOS if directive. But I am still getting default pins on iOS
Is the code in AddAnnotation
executed?
You directed me to the right code to debug. The AddAnnotation
was executed but Map
in the following code was null:
var nativeMap = (MauiMKMapView)pin.Map?.Handler?.PlatformView;
After setting the Map value in the ItemTemplate of the Map the code worked.