我正在为Android创建一个使用Maps API的应用,我想使用GroundOverlay
。
这是我的实际onMapReady
:
@Override
public void onMapReady(GoogleMap googleMap) {
mMap = googleMap;
//defining coordinates of image bounds
LatLngBounds imageMapBounds = new LatLngBounds(
new LatLng(46.709064, 2.888008),
new LatLng(46.729014, 2.918522)
);
//adding image and coordinates to the GroundOverlay
GroundOverlayOptions imageMapOptions = new GroundOverlayOptions()
.image(BitmapDescriptorFactory.fromAsset("map.png"))
.positionFromBounds(imageMapBounds);
//adding GroundOverlay to the map
GroundOverlay map = mMap.addGroundOverlay(imageMapOptions);
}
我已经尝试过在谷歌上发现的其他方法,但在所有情况下,都会发生以下错误:
E/AndroidRuntime: FATAL EXCEPTION: main
Process: fr.rm_jln.parilly, PID: 29898
com.google.maps.api.android.lib6.common.apiexception.b: Failed to decode image. The provided image must be a Bitmap.
at com.google.maps.api.android.lib6.impl.h.a(:com.google.android.gms.dynamite_dynamitemodulesb@12673025@12.6.73 (040408-194189626):9)
at com.google.maps.api.android.lib6.impl.o.a(:com.google.android.gms.dynamite_dynamitemodulesb@12673025@12.6.73 (040408-194189626):7)
at com.google.maps.api.android.lib6.impl.bj.<init>(:com.google.android.gms.dynamite_dynamitemodulesb@12673025@12.6.73 (040408-194189626):37)
at com.google.maps.api.android.lib6.impl.bc.a(:com.google.android.gms.dynamite_dynamitemodulesb@12673025@12.6.73 (040408-194189626):539)
at com.google.android.gms.maps.internal.l.onTransact(:com.google.android.gms.dynamite_dynamitemodulesb@12673025@12.6.73 (040408-194189626):98)
at android.os.Binder.transact(Binder.java:499)
at com.google.android.gms.internal.maps.zza.transactAndReadException(Unknown Source)
at com.google.android.gms.maps.internal.zzg.addGroundOverlay(Unknown Source)
at com.google.android.gms.maps.GoogleMap.addGroundOverlay(Unknown Source)
at fr.rm_jln.parilly.DisplayPathActivity.onMapReady(DisplayPathActivity.java:100)
at com.google.android.gms.maps.zzak.zza(Unknown Source)
at com.google.android.gms.maps.internal.zzaq.dispatchTransaction(Unknown Source)
at com.google.android.gms.internal.maps.zzb.onTransact(Unknown Source)
at android.os.Binder.transact(Binder.java:499)
at fr.b(:com.google.android.gms.dynamite_dynamitemodulesb@12673025@12.6.73 (040408-194189626):20)
at com.google.android.gms.maps.internal.bg.a(:com.google.android.gms.dynamite_dynamitemodulesb@12673025@12.6.73 (040408-194189626):5)
at com.google.maps.api.android.lib6.impl.be.run(:com.google.android.gms.dynamite_dynamitemodulesb@12673025@12.6.73 (040408-194189626):5)
at android.os.Handler.handleCallback(Handler.java:761)
at android.os.Handler.dispatchMessage(Handler.java:98)
at android.os.Looper.loop(Looper.java:156)
at android.app.ActivityThread.main(ActivityThread.java:6523)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:942)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:832)
如第三行所述,GroundOverlay
仅接受.bmp
张图片。
问题是我的图像在.png
时重约15Mo,在.bmp
时重约500Mo。 .bmp
中的图片无法压缩,如果我想要最低质量,我就无法将其调整得更小。
所以我的问题是:如果没有太重的文件,我怎么能使用GroundOverlay?