GoogleMaps custom renderer in iOS -> NPE

AndreaBellittoAndreaBellitto ITMember
edited March 2017 in Xamarin.Forms

I'm writing a project with a pcl and ios components. I'm following this sample:

https://github.com/xamarin/xamarin-forms-samples/blob/master/CustomRenderers/Map/Pin

Using it in conjunction with Xamarin.Forms.GoogleMaps NuGet package.

I'm facing a problem inside iOS renderer, because on row number 37 https://github.com/xamarin/xamarin-forms-samples/blob/master/CustomRenderers/Map/Pin/iOS/CustomMapRenderer.cs#L37 i will get always

var nativeMap = null

I can't understand what I'm missing

EDIT:
Debugging I get some more information. The problem seems to be Control as MKMapView casting, infact that casting returns null, Control seems to be GMSMapView type instead of MKMapView.

How to go ahead of this problem???

Posts

  • RyanSmith.9175RyanSmith.9175 USMember ✭✭

    Have you figured out this issue? I am also trying to implement custom renderer for maps in iOS with google maps

  • You could try smth like this. I wont go into details how pass Pins or other data.

    public class GMapRenderer : ViewRenderer<ObjectsGMap, MapView>
        {
            private MapView mapView;
            protected override void OnElementChanged(ElementChangedEventArgs<ObjectsGMap> e)
            {
                base.OnElementChanged(e);
                if (e.OldElement != null || Element == null)
                    return;
                var formsElement = Element as ObjectsGMap;
                if (Control == null)
                {
                    mapView = new MapView();
                    SetNativeControl(mapView);
                }
            }
        }
    
Sign In or Register to comment.