0
我想快照谷歌地图图像后,我将地图设置为折线的界限。我使用了StackExchange上独立的代码示例来执行单独运行的moveToBounds()和Snapshot,但是在更新映射之前,按顺序运行快照时,映射图像是快照。我假设我需要插入一个OnCameraChangeListener,但我无法使它工作。我需要以某种方式嵌套回调?请指教。安卓谷歌地图更新摄像头拍摄前快照故障
public void mapCapture() {
moveToBounds(gpsTrackingPolyline);
mMap.snapshot(new GoogleMap.SnapshotReadyCallback() {
public void onSnapshotReady(Bitmap bitmap) {
// Write image to disk
try {
File bmpFile = new File(getApplicationContext().getExternalFilesDir(null), DEFAULT_BMP_FILENAME);
FileOutputStream out = new FileOutputStream(bmpFile);
bitmap.compress(Bitmap.CompressFormat.PNG, 90, out);
} catch (Exception e) {
e.printStackTrace();
}
}
});
}
private void moveToBounds(Polyline p)
{
LatLngBounds.Builder builder = new LatLngBounds.Builder();
List<LatLng> arr = p.getPoints();
for(int i = 0; i < arr.size();i++){
builder.include(arr.get(i));
}
LatLngBounds bounds = builder.build();
int padding = 40; // offset from edges of the map in pixels
CameraUpdate cu = CameraUpdateFactory.newLatLngBounds(bounds, padding);
mMap.animateCamera(cu);
}