themronion / Maui.GoogleMaps

Map library for MAUI using Google maps API
https://www.nuget.org/packages/Onion.Maui.GoogleMaps/
MIT License
79 stars 35 forks source link

Support for MAUI Embedding #2

Closed andreas-nesheim closed 1 year ago

andreas-nesheim commented 1 year ago

SUMMARY

Hi! Thank you very much for your work in porting this library to .NET MAUI, it is greatly appreciated!

We have an app that utilizes MAUI Embedding to use MAUI pages in ".NET for Android" and ".NET for iOS" apps (previously Xamarin.Android and Xamarin.iOS). I was hoping to use your library in this app, but it seems that the map registration doesn't seem to take effect when using this approach. Do you know if this is possible at all with this approach, or if this is something that's possible to implement? When I try to do this from the iOS project, I get this error at runtime:

ObjCRuntime.ObjCException: 'Objective-C exception thrown.  Name: GMSServicesException Reason: Google Maps SDK for iOS must be initialized via [GMSServices provideAPIKey:...] prior to use

On Android I just get a NullReferenceException at runtime.

DETAILS

The use-case involves having one class library for the iOS/Android app and one class library where the MAUI pages are located. I use the embedding technique (as described in the previous link) and I use the host builder to add the .UseGoogleMaps() in my AppDelegate.cs / MainActivity.cs. I've attached a repro of a project that uses MAUI embedding and that tries to use this package.

I understand that this embedding technique might not be all that used, but it would be great if there is a way to make this package work with this setup.

PLATFORMS

MAUIEmbedding.zip

themronion commented 1 year ago

I'll take a look

themronion commented 1 year ago

@andreas-nesheim just init the maps manually before .UseGoogleMaps()

 MauiGoogleMaps.Init("Key"); //ios
 MauiGoogleMaps.Init(this, savedInstanceState); //android
andreas-nesheim commented 1 year ago

Great, I'll have a try next week when I'm back at work!

andreas-nesheim commented 1 year ago

This worked perfectly, thank you very much for your help!