我必须用谷歌地图发布的新的“快照制造商”解决这个问题,但我不知道如何做到这一点.
可以单独给我一个简单的例子吗?
可以单独给我一个简单的例子吗?
这是我的代码:
public class MainActivity extends Activity { static LatLng HAMBURG = new LatLng(47.524749,21.632745); GoogleMap map; File dbFile; private File imageFile; @SuppressLint("NewApi") @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); PolylineOptions line = new PolylineOptions(); map = ((MapFragment) getFragmentManager().findFragmentById(R.id.map)) .getMap(); /* * Adatbázis */ try { dbFile = getDatabasePath("/mnt/sdcard/Download/TeleSensors.db"); } catch (Exception e) { } sqliteDatabase myDataBase = sqliteDatabase.openDatabase( dbFile.getAbsolutePath(),null,sqliteDatabase.OPEN_READONLY); Cursor curTAB = myDataBase.rawQuery("SELECT * FROM GPS_Values;",null); Integer count = 0; while (curTAB.moveToNext()) { String s_latitude = curTAB.getString(1); String s_longitude = curTAB.getString(2); count++; double latitude = Double.parseDouble(s_latitude); double longitude = Double.parseDouble(s_longitude); line.add(new LatLng(latitude,longitude)); Log.i("Coordinates",s_latitude.toString() + " --- " + s_longitude.toString()); } curTAB.close(); myDataBase.close(); // adatbázis vége map.addPolyline(line); // map.setMapType(GoogleMap.MAP_TYPE_HYBRID); // map.setMapType(GoogleMap.MAP_TYPE_NONE); map.setMapType(GoogleMap.MAP_TYPE_NORMAL); // map.setMapType(GoogleMap.MAP_TYPE_SATELLITE); // map.setMapType(GoogleMap.MAP_TYPE_TERRAIN); // Move the camera instantly to hamburg with a zoom of 15. map.moveCamera(CameraUpdateFactory.newLatLngZoom(HAMBURG,15)); // Zoom in,animating the camera. map.animateCamera(CameraUpdateFactory.zoomTo(15),2000,null); }
}
谢谢你很好玩!
解决方法
您必须在按钮侦听器中调用Google maps快照方法,因为如果您应该太早地使用它,则会给您错误位图宽度必须大于0或类似于此.
这是代码
这是代码
private void button_listener() { Button button = (Button) findViewById(R.id.button1); button.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { SnapshotReadyCallback callback = new SnapshotReadyCallback() { Bitmap bitmap; @Override public void onSnapshotReady(Bitmap snapshot) { bitmap = snapshot; try { FileOutputStream out = new FileOutputStream("/mnt/sdcard/Download/TeleSensors.png"); bitmap.compress(Bitmap.CompressFormat.PNG,90,out); } catch (Exception e) { e.printStackTrace(); } } }; map.snapshot(callback); } }); }