0

In post Xamarin, C#, Google Maps fragment not responding to any commands. (i.e MoveCamera), @Robbit, posts a github package which works just fine with the included Target 8.1 and current-at-that-time Nugut packages.

However, as I update the project with latest packages and target 11 and min 10, and rebuild, the code now gets an error:

SupportMapFragment mapFragment = (SupportMapFragment)SupportFragmentManager.FindFragmentById(Resource.Id.map);
mapFragment.GetMapAsync(this);

Severity Code Description Project File Line Suppression State Error CS0030 Cannot convert type 'Android.Support.V4.App.Fragment' to 'Android.Gms.Maps.SupportMapFragment' App46 GoogleMapXamarinTest-master\App46\MainActivity.cs 29 Active

Visual Studio showing the can't convert fragement pic

I do not understand why -- can someone please explain ?

karhukoti
  • 1
  • 3
  • check this question https://stackoverflow.com/questions/23164459/cannot-convert-type-android-support-v4-app-fragment-to-android-gms-maps-mapfr – Adrain Nov 26 '21 at 05:38
  • Does not seem to work as in my case where now I have min build version as 10 and target as 11, while using latest nugut packages. As I mention, using the earlier build values it does. Something has changed. Or, am I missing a subtle point ? – karhukoti Nov 26 '21 at 07:46
  • @AdrainZhu-MSFT, as mentioned in the thread you reference, it is said to use SupportMapFragment, - that is what my code snippet at top is doing. As an experiment, my line of code using SupportMapFragment works using Min 8.0 and Target 8.1. But as I moved the code to build with Min 10 and Target 11, I start getting the errors. What does one do now ? – karhukoti Nov 26 '21 at 08:19
  • did you update your app to use Jetpack (AndroidX); like this instruction shows https://developer.android.com/jetpack/androidx/migrate – Adrain Nov 26 '21 at 08:32
  • No, unaware of that -- I will read and try it and respond back -- thanks. – karhukoti Nov 26 '21 at 10:23
  • @AdrainZhu-MSFT, so I can see the following AndroidX FragmentManager now per: var x = AndroidX.Fragment.App.FragmentManager.FindFragmentById(Resource.Id.mymapfragmentID); but this gives me: Error CS0120 An object reference is required for the non-static field, method, or property 'FragmentManager.FindFragmentById(int)' GPSSatellite5 C:\code\Xamarin\GPSSatellite6\GPSSatellite5\MapActivity.cs Why would this happen ? – karhukoti Nov 26 '21 at 10:55
  • @AdrainZhu-MSFT, ah - I see since in AdroidX, the FragmentManager is an abstract class, so I have inherited to a new class and call the method... will continue on shortly with my findings. – karhukoti Nov 26 '21 at 11:55
  • OK, here is the answer and it does include using the AndroidX: myFragmentManager fragmentManager = new myFragmentManager(); var mapFragment = (SupportMapFragment)fragmentManager.FindFragmentById(Resource.Id.mymapfragmentID); And expand the class: public class myFragmentManager : AndroidX.Fragment.App.FragmentManager { } – karhukoti Nov 26 '21 at 16:22

0 Answers0