У меня проблема с картами google BitmapDescriptor
при создании значка для MarkerOptions
с помощью VectorDrawable
, API 5.0 +
Метод, используемый для создания:
@NonNull
private BitmapDescriptor getBitmapDescriptor(int id) {
return BitmapDescriptorFactory.fromResource(id);
}
Все отлично работает, когда аргумент id
содержит png drawable, однако если я попробую его с VectorDrawable
, определенным в xml, приложение всегда сбой, когда googleMap.addMarker(marker)
(BitmapDescriptor
не равно null).
11-05 10:15:05.213 14536-14536/xxx.xxxxx.app E/AndroidRuntime: FATAL EXCEPTION: main
Process: xxx.xxxxx.app, PID: 14536
java.lang.NullPointerException
at com.google.a.a.ae.a(Unknown Source)
at com.google.maps.api.android.lib6.d.dn.<init>(Unknown Source)
at com.google.maps.api.android.lib6.d.dm.a(Unknown Source)
at com.google.maps.api.android.lib6.d.ag.<init>(Unknown Source)
at com.google.maps.api.android.lib6.d.eu.a(Unknown Source)
at com.google.android.gms.maps.internal.j.onTransact(SourceFile:167)
at android.os.Binder.transact(Binder.java:380)
at com.google.android.gms.maps.internal.IGoogleMapDelegate$zza$zza.addMarker(Unknown Source)
at com.google.android.gms.maps.GoogleMap.addMarker(Unknown Source)
at xxx.xxxxx.app.ui.details.DetailActivity.lambda$initGoogleMaps$23(DetailActivity.java:387)
at xxx.xxxxx.app.ui.details.DetailActivity.access$lambda$10(DetailActivity.java)
at xxx.xxxxx.app.ui.details.DetailActivity$$Lambda$13.onMapReady(Unknown Source)
at com.google.android.gms.maps.SupportMapFragment$zza$1.zza(Unknown Source)
at com.google.android.gms.maps.internal.zzl$zza.onTransact(Unknown Source)
at android.os.Binder.transact(Binder.java:380)
at com.google.android.gms.maps.internal.av.a(SourceFile:82)
at com.google.maps.api.android.lib6.d.fa.run(Unknown Source)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5221)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:899)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:694)
Не имеет значения, как я извлекаю drawable, попытался создать растровое изображение, используя BitmapFactory.fromResources
и позже BitmapDescritpionFactory.fromBitmap
, но результаты одинаковы. Он просто не будет работать с вектором. Пробовал и разные векторы, но, похоже, проблема с вектором не является проблемой.
Кто-нибудь знает, как исправить эту ошибку?
@edit
Похоже, проблема была не в самом BitmapDescriptior
, а в загрузке VectorDrawable
, которая возвращала неправильное растровое изображение. Однако решение, предлагаемое в ответ, по-прежнему прекрасное.