Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using Google Maps on Xamarin.Forms for Android

So we need to create an app that renders a map and we are currently using Xamarin.Forms to integrate it. However, we will not use Xamarin.Forms.Maps since we have to use the Google Maps API for iOS and not its native map which is MapKit.

My question is, how do I integrate this component https://components.xamarin.com/view/googleplayservices-maps in Xamarin.Forms?

like image 659
AlexaMayer Avatar asked Nov 08 '22 22:11

AlexaMayer


1 Answers

You can inject Google Map (for Android or iOS) to Xamarin.Forms's view.

Example in Android:

public class AndroidMapRenderer : ViewRenderer
{
    protected override void OnElementChanged(ElementChangedEventArgs<View> e)
    {
        base.OnElementChanged(e);

        var mapView = new Android.Gms.Maps.MapView(Context);
        SetNativeControl(mapView);
    }
}

This way is "custom renderer".

Please read these:

  • Customizing Controls on Each Platform - Xamarin
  • Customizing a Map - Xamarin
like image 175
amay077 Avatar answered Nov 14 '22 21:11

amay077