如何利用谷歌地图V2快照? [英] How to take google Maps v2 snapshot?

查看:318
本文介绍了如何利用谷歌地图V2快照?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要解决这个与这是在谷歌地图中实现的新的快照制造者释放威严,但我不'知道如何做到这一点。 可以somone给我一个简单的例子?

i have to solve this with the new "snapshot maker" which is implemented in the google maps release august but i dont' know how to do this. Can somone give me a simple example?

这是我的code:

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


}

}

感谢您非常mouch!

Thank you very mouch!

推荐答案

您必须调用谷歌地图快照方法的一个按钮监听器,因为如果你应该把它的太早,它会给你错误位图的宽度必须大于0 大或类似这样的东西。 这里是code

You have to call the Google maps snapshot method in a button listener because if you should take it too early, it will give you error bitmap width has to be larger than 0 or something like this. Here is the code

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

这篇关于如何利用谷歌地图V2快照?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆