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
Call MapsInitializer.initialize(getApplicationContext())
in the onCreate()
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.
Call following in onCreate()
try {
MapsInitializer.initialize(getApplicationContext());
} catch (GooglePlayServicesNotAvailableException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
Move your code to be called onMapReady()
, a callback provided by the GoogleMaps API.
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.
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 {}