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);
}