“IBitmapDescriptorFactory is not initialized” error

后端 未结 7 791
小鲜肉
小鲜肉 2021-01-31 13:52

I\'m trying to get a marker with an custom icon in Google Maps Android API v2. I just changed one of the examples Google provides. I added .icon(BitmapDescriptorFactory.fr

相关标签:
7条回答
  • 2021-01-31 13:59

    Call MapsInitializer.initialize(getApplicationContext()) in the onCreate()

    0 讨论(0)
  • 2021-01-31 14:06

    See Custom marker in google maps in android with vector asset icon.

    In my case I had markers over Google Maps. But on API 19 emulator there is a problem with Google Play Services. So this error is misleading, Google Play Services tried to create BitmapDescriptor, but could not.

    You should create markers in onMapReady(), also move there any other code, working with Google Maps.

    If you have problems with showing Google Maps on Android 4, maybe you should downgrade a library from 16.1.0 to 16.0.0, see https://stackoverflow.com/a/54772374/2914140. But if you do so, you will get a crash on Androif 9, see Google Maps crashing on Android Pie.

    0 讨论(0)
  • 2021-01-31 14:08

    Call following in onCreate()

    try {
            MapsInitializer.initialize(getApplicationContext());
        } catch (GooglePlayServicesNotAvailableException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    
    0 讨论(0)
  • 2021-01-31 14:11

    Move your code to be called onMapReady(), a callback provided by the GoogleMaps API.

    0 讨论(0)
  • 2021-01-31 14:11

    This happened to me and finally In my case what I could find was the google play services were not installed. So installed them and app did not crash. So may be one can put try and a dialog saying so in the catch block.

    0 讨论(0)
  • 2021-01-31 14:12
      GoogleApiAvailability googleApiAvailability=GoogleApiAvailability.getInstance();
    
      int status=googleApiAvailability.isGooglePlayServicesAvailable(getActivity());
    
    
    
      if (status != ConnectionResult.SUCCESS) {
            int requestCode = 10;
            Dialog dialog = googleApiAvailability.getErrorDialog(getActivity(),status,requestCode);
            dialog.show();
        }else {}
    
    0 讨论(0)
提交回复
热议问题