GoogleMap Android API V2捕获错误

时间:2013-08-21 12:02:07

标签: java android google-maps screenshot android-maps-v2

我已经尝试了@ Tarsem回答,但发生致命错误我能知道为什么吗? @ Tarsem回答: https://stackoverflow.com/a/18308611/2398886

< ---这些是我在eclipse中的错误代码:--->

08-21 18:52:23.399: W/dalvikvm(29376): threadid=1: thread exiting with uncaught exception (group=0x40018578)

08-21 18:52:23.409: E/AndroidRuntime(29376): FATAL EXCEPTION: main

08-21 18:52:23.409: E/AndroidRuntime(29376): java.lang.NoClassDefFoundError: com.example.testing01.MainActivity2$6

08-21 18:52:23.409: E/AndroidRuntime(29376): at com.example.testing01.MainActivity2.CaptureMapScreen(MainActivity2.java:410)

08-21 18:52:23.409: E/AndroidRuntime(29376): at com.example.testing01.MainActivity2$3.onClick(MainActivity2.java:182)

08-21 18:52:23.409: E/AndroidRuntime(29376): at android.view.View.performClick(View.java:2485)

08-21 18:52:23.409: E/AndroidRuntime(29376): at android.view.View$PerformClick.run(View.java:9080)

08-21 18:52:23.409: E/AndroidRuntime(29376): at android.os.Handler.handleCallback(Handler.java:587)

08-21 18:52:23.409: E/AndroidRuntime(29376): at android.os.Handler.dispatchMessage(Handler.java:92)

08-21 18:52:23.409: E/AndroidRuntime(29376): at android.os.Looper.loop(Looper.java:130)

08-21 18:52:23.409: E/AndroidRuntime(29376): at android.app.ActivityThread.main(ActivityThread.java:3687)

08-21 18:52:23.409: E/AndroidRuntime(29376): at java.lang.reflect.Method.invokeNative(Native Method)

08-21 18:52:23.409: E/AndroidRuntime(29376): at java.lang.reflect.Method.invoke(Method.java:507)

08-21 18:52:23.409: E/AndroidRuntime(29376): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run (ZygoteInit.java:867)

08-21 18:52:23.409: E/AndroidRuntime(29376): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:625)

08-21 18:52:23.409: E/AndroidRuntime(29376): at dalvik.system.NativeStart.main(Native Method)

< ---这些是我在eclipse中的错误代码:--->

这些是我的编码,是我的编码任何错误吗?

public void CaptureMapScreen() 
 {
 SnapshotReadyCallback callback = new SnapshotReadyCallback() {
             Bitmap bitmap;

             @Override
             public void onSnapshotReady(Bitmap snapshot) {
                 // TODO Auto-generated method stub
                 bitmap = snapshot;
                 try {
                     FileOutputStream out = new FileOutputStream("/mnt/sdcard/"
                         + "MyMapScreen" + System.currentTimeMillis()
                         + ".png");

                     // above "/mnt ..... png" => is a storage path (where image will be stored) + name of image you can customize as per your Requirement

                     bitmap.compress(Bitmap.CompressFormat.PNG, 90, out);
                 } catch (Exception e) {
                     e.printStackTrace();
                 }
             }
         };

         map.snapshot(callback);

         // myMap is object of GoogleMap +> GoogleMap myMap;
         // which is initialized in onCreate() => 
         // myMap = ((SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map_pass_home_call)).getMap();
 }

我的停止按钮功能:

//End Button Function
 Button timerStopButton = (Button) findViewById(R.id.btnTimerStop);      
 timerStopButton.setOnClickListener(new View.OnClickListener() {
        public void onClick(View view){          

            String latitude3=Double.toString(latitude1);
            String latitude4=Double.toString(latitude2);
            String longitude3=Double.toString(longitude1);
            String longitude4=Double.toString(longitude2);
            String Kcalories=String.format("%.2f", calories);

            Intent intent = new Intent(view.getContext(),NewDataActivity.class);
            intent.putExtra("lat1", latitude3);
            intent.putExtra("lat2", latitude4);
            intent.putExtra("long1", longitude3);
            intent.putExtra("long2", longitude4);
            intent.putExtra("timer", timerStop1);
            intent.putExtra("distance", distance2 + " m");
            intent.putExtra("Ccalories", Kcalories + " kcal");
            Toast.makeText(getApplicationContext(), "Calories (kcal):" + Kcalories, Toast.LENGTH_LONG).show();
            startActivity(intent);                                          

            try {
                CaptureMapScreen();
            } catch (Exception e) {
                // TODO: handle exception
                e.printStackTrace();
            }

            //kill task timer and other 
            int pid = android.os.Process.myPid();
            android.os.Process.killProcess(pid);
        }                

 });

我的编码是否有任何错误或我的逻辑任何问题? 谁能帮我?谢谢:))

1 个答案:

答案 0 :(得分:1)

注意您的捕获地图屏幕的代码是正确的,如果您仍然感到困惑

请确保以下每一步:

以下是使用示例

捕获Google Map V2屏幕截图的步骤

第1步。打开Android Sdk Manager (Window > Android Sdk Manager)然后Expand Extras现在update/install Google Play Services to Revision 10如果已经installed

,请忽略此步骤

在此处阅读备注https://developers.google.com/maps/documentation/android/releases#august_2013

第2步。 Restart Eclipse

第3步。 import com.google.android.gms.maps.GoogleMap.SnapshotReadyCallback;

第4步。制作方法以捕获/存储地图的屏幕/图像,如下所示

public void CaptureMapScreen() 
{
SnapshotReadyCallback callback = new SnapshotReadyCallback() {
            Bitmap bitmap;

            @Override
            public void onSnapshotReady(Bitmap snapshot) {
                // TODO Auto-generated method stub
                bitmap = snapshot;
                try {
                    FileOutputStream out = new FileOutputStream("/mnt/sdcard/"
                        + "MyMapScreen" + System.currentTimeMillis()
                        + ".png");

                    // above "/mnt ..... png" => is a storage path (where image will be stored) + name of image you can customize as per your Requirement

                    bitmap.compress(Bitmap.CompressFormat.PNG, 90, out);
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        };

        myMap.snapshot(callback);

        // myMap is object of GoogleMap +> GoogleMap myMap;
        // which is initialized in onCreate() => 
        // myMap = ((SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map_pass_home_call)).getMap();
}

第5步。现在调用此CaptureMapScreen()方法来捕获图像

在我的情况下,我calling this method on Button click in my onCreate()工作正常

<强>像:

Button btnCap = (Button) findViewById(R.id.btnTakeScreenshot);
    btnCap.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            // TODO Auto-generated method stub
            try {
                CaptureMapScreen();
            } catch (Exception e) {
                // TODO: handle exception
                e.printStackTrace();
            }

        }
    });

检查文档herehere