Sha*_*mog 6 android google-maps codenameone google-maps-android-api-2
我正在尝试使用此处提到的API获取Google Maps V2地图的屏幕截图,但这似乎总是返回底部带有Google徽标的白色图片.如果它不是徽标,我会确定这根本不起作用,但徽标意味着发生了一些事情并且地图没有显示.这大致就是我正在做的事情:
mv.setVisibility(View.VISIBLE);
mv.getMap().snapshot(new GoogleMap.SnapshotReadyCallback() {
public void onSnapshotReady(Bitmap snapshot) {
synchronized(finished) {
finished[0] = snapshot;
finished.notify();
}
}
});
Run Code Online (Sandbox Code Playgroud)
我尝试了多种不同的方法,包括将图像绘制到不同的图像和各种其他尝试.
唯一的主要区别是我使用MapView而不是MapFragment,因为我在这里无法切换到使用片段的一些技术问题.
要拍摄快照,您需要等待地图加载然后拍摄快照.
详细信息:实现SnapshotReadyCallback和OnMapLoadedCallback.
import com.google.android.gms.maps.GoogleMap.SnapshotReadyCallback;
import com.google.android.gms.maps.GoogleMap.OnMapLoadedCallback;
public class KmlReader extends ActionBarActivity implements
SnapshotReadyCallback,
OnMapLoadedCallback {
Run Code Online (Sandbox Code Playgroud)
...
if (mMap == null) {
// Try to obtain the map from the SupportMapFragment.
// mMap = mMapFragment.getMap();
// // Check if we were successful in obtaining the map.
// Try to obtain the map from the SupportMapFragment.
mMap = ((SupportMapFragment) getSupportFragmentManager()
.findFragmentById(R.id.map)).getMap();
// use the settings maptype
// Check if we were successful in obtaining the map.
if (mMap != null) {
mMap.setOnMapLoadedCallback(this);
Run Code Online (Sandbox Code Playgroud)
...
@Override
public void onMapLoaded() {
if (mMap != null) {
mMap.snapshot(this);
}
}
Run Code Online (Sandbox Code Playgroud)
当它触发时你有一个真正的位图.
@Override
public void onSnapshotReady(Bitmap bm) {
if (CheckStorage.isExternalStorageWritable()) {
int newHeight = 96;
int newWidth = 96;
int width = bm.getWidth();
int height = bm.getHeight();
float scaleWidth = ((float) newWidth) / width;
float scaleHeight = ((float) newHeight) / height;
// create a matrix for the manipulation
Matrix matrix = new Matrix();
// resize the bit map
matrix.postScale(scaleWidth, scaleHeight);
// recreate the new Bitmap
Bitmap resizedBitmap = Bitmap.createBitmap(bm, 0, 0, width, height,
matrix, false);
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
3639 次 |
| 最近记录: |