GoogleMap的API的Andr​​oid V2捕获错误 [英] GoogleMap Android API V2 Capture Error

查看:195
本文介绍了GoogleMap的API的Andr​​oid V2捕获错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试@ Tarsem 已经回答,但有致命错误发生,我可以知道为什么吗?
@ Tarsem 回答:
<一href=\"http://stackoverflow.com/a/18308611/2398886\">http://stackoverflow.com/a/18308611/2398886

I try @Tarsem answer already but have fatal error occur can I know why? @Tarsem answer: http://stackoverflow.com/a/18308611/2398886

&LT; ---这些都是我的错误codeS在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)

&LT; ---这些都是我的错误codeS在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);
        }                

 });

这是我的编码有任何错误或我的逻辑的万阿英,蒋达清?
谁能帮助我?感谢:)

Is it my coding have any bug or my logic any probelm? can anyone help me? thanks :)

推荐答案

注意您的code捕获地图画面是正确的,如果你仍比

Note Your code to Capture Map Screen is Correct and if still you have confusion than

请确保以下每个步骤: -

下面是捕捉到谷歌地图V2的屏幕截图中的步骤

Below are the steps to capture screen shot of Google Map V2 with example

第1步打开 Android的SDK管理器(窗口&GT;的Andr​​oid SDK管理器)。然后展开额外现在更新/安装谷歌Play服务修订10 忽略这一步,如果已经安装

Step 1. open Android Sdk Manager (Window > Android Sdk Manager) then Expand Extras now update/install Google Play Services to Revision 10 ignore this step if already installed

阅读说明这里 https://developers.google.com/maps/documentation /安卓/版本#august_2013

第2步 重启Eclipse

第3步 进口com.google.android.gms.maps.GoogleMap.SnapshotReadyCallback;

第4步。请方法来捕获地图/存储画面/图像像下面

Step 4. Make Method to Capture/Store Screen/image of Map like below

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

Step 5. Now call this CaptureMapScreen() method where you want to capture the image

在我的情况我是调用按钮单击此方法在我的onCreate()这是工作的罚款

in my case i am calling this method on Button click in my onCreate() which is working fine

这样的:

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

        }
    });

检查文件<一个href=\"https://developers.google.com/maps/documentation/android/reference/com/google/android/gms/maps/GoogleMap#snapshot%28com.google.android.gms.maps.GoogleMap.SnapshotReadyCallback,%20android.graphics.Bitmap%29\"相对=nofollow>这里和<一个href=\"https://developers.google.com/maps/documentation/android/reference/com/google/android/gms/maps/GoogleMap.SnapshotReadyCallback\"相对=nofollow>这里

这篇关于GoogleMap的API的Andr​​oid V2捕获错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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