I am currently working on a cross platform (iOS and Android) project that uses the map control. Adding map markers results in either crashing the app or not displaying markers in iOS depending on the how I am adding the markers. Note: both methods work as expected on Android.
1. The first method is adding them through the .xaml file. This results in the app crashing when navigating to the map page with the following exception:
{System.NullReferenceException: Object reference not set to an instance of an object
at Syncfusion.SfMaps.XForms.iOS.SfMapsRenderer.ConvertFormsToNative (Xamarin.Forms.DataTemplate view, CoreGraphics.CGRect size, Syncfusion.SfMaps.XForms.MapMarker marker) [0x00000] in <9459282c908f43efb3825079168468e4>:0
at Syncfusion.SfMaps.XForms.iOS.DelegateMapping.DrawMarker (Syncfusion.SfMaps.iOS.SFMap map, Syncfusion.SfMaps.iOS.SFMapMarker marker, CoreGraphics.CGPoint point) [0x00032] in <9459282c908f43efb3825079168468e4>:0
at Syncfusion.SfMaps.iOS.SFMapLayer.RefreshMarkers () [0x00053] in <67887b5007aa41efb7e1a8781f476ce5>:0
at Syncfusion.SfMaps.iOS.SFMapLayer.LayoutSubviews () [0x00730] in <67887b5007aa41efb7e1a8781f476ce5>:0
at (wrapper managed-to-native) UIKit.UIApplication:UIApplicationMain (int,string[],intptr,intptr)
at UIKit.UIApplication.Main (System.String[] args, System.IntPtr principal, System.IntPtr delegate) [0x00005] in /Users/builder/data/lanes/5665/db807ec9/source/xamarin-macios/src/UIKit/UIApplication.cs:79
at UIKit.UIApplication.Main (System.String[] args, System.String principalClassName, System.String delegateClassName) [0x00038] in /Users/builder/data/lanes/5665/db807ec9/source/xamarin-macios/src/UIKit/UIApplication.cs:63
at CTG.iOS.Application.Main (System.String[] args) [0x00002] in C:\Users\...\iOS\Main.cs:19 }
The .xaml looked like:
maps:SfMaps Grid.Row="2" IsVisible="false" x:Name="Map">
<maps:SfMaps.Layers>
<maps:ShapeFileLayer ShapeSelected="Handle_ShapeSelected"
EnableSelection="true"
ShowMapItems="true"
ShapeIDPath="StateName" ShapeIDTableField="STATE_NAME" x:Name="MapLayer">
<maps:ShapeFileLayer.Uri>
<OnPlatform x:TypeArguments="x:String">
<OnPlatform.Platforms>
<On Platform="iOS" Value="states.shp" />
<On Platform="Android" Value="usa_state.shp" />
</OnPlatform.Platforms>
</OnPlatform>
</maps:ShapeFileLayer.Uri>
<maps:ShapeFileLayer.MarkerSettings>
<maps:MapMarkerSetting IconColor="{StaticResource Exception}" MarkerIcon="Diamond"/>
</maps:ShapeFileLayer.MarkerSettings><maps:ShapeFileLayer.MarkerSettings>
<maps:MapMarkerSetting IconColor="{StaticResource Exception}" MarkerIcon="Diamond"/>
</maps:ShapeFileLayer.MarkerSettings>
<maps:ShapeFileLayer.Markers>
<!-- California -->
<maps:MapMarker Latitude = "37" Longitude = "-120"/>
<!-- Washington -->
<maps:MapMarker Latitude = "47.680415" Longitude = "-120.050996"/>
<!-- Illinois -->
<maps:MapMarker Latitude = "40.270476" Longitude = "-89.157629"/>
<!-- Virginia -->
<maps:MapMarker Latitude = "37.909806" Longitude = "-78.303137"/>
</maps:ShapeFileLayer.Markers>
<maps:ShapeFileLayer.ShapeSettings>
<maps:ShapeSetting ShapeFill="#CFD7E4" ShapeStroke="#FFFFFF" ShapeColorValuePath="Status">
<maps:ShapeSetting.ColorMappings>
<maps:EqualColorMapping Value="0" LegendLabel="Not Available" Color="{StaticResource NotAvailable}"/>
<maps:EqualColorMapping Value="1" LegendLabel="Available" Color="{StaticResource Available}"/>
<maps:EqualColorMapping Value="1" LegendLabel="Exception" Color="{StaticResource Exception}"/>
</maps:ShapeSetting.ColorMappings>
</maps:ShapeSetting>
</maps:ShapeFileLayer.ShapeSettings>
</maps:ShapeFileLayer>
</maps:SfMaps.Layers>
</maps:SfMaps>
2. The second method was adding the marker during "OnAppearing()" and resulted in the map appearing without markers.
public void SetMarkers()
{
MapMarker usa = new MapMarker();
usa.Latitude = "37";
usa.Longitude = "-120";
usa.Label = "United States";
MapLayer.Markers.Add(usa);
}