计算使用GPS累积的距离(不能调用run方法) [英] calculating accumulated distance using GPS(cannot call run method)

查看:248
本文介绍了计算使用GPS累积的距离(不能调用run方法)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我仍然工作的一个项目我也问一个问题就在这里。它是计算累积距离一个人在一段时间后前往或运行。
我不知道我是否应该开始一个新的问题或从第一个我问第一个持续,因为我进步了很多,因为当时和我的codeS很多不同与不同的错误。我试图使用Eclipse中的调试器,但它没有工作,我不明白。
距离积累的部分是什么困扰着我,我使用Runnable的run方法。但我的应用程序没有达到Run方法时坠毁。
当我preSS启动的举动,它显示第二个值成功和主题开始,这是只是为了显示我它达到这一点。但它并没有显示运行运行,因此它永远也达不到的run方法。
当我试codeS,我输入使用模拟器位置数据。它有什么不同的效果时,它是实时的?我一直以为它是不可能在笔记本电脑发展codeS时使用实时。如果有,可能有人告诉我吗?从研究,所有的人我见过使用仿真器。我一个新的用户,所以不知道如何使用调试器,我尝试过,但它并没有显示任何东西。

当我preSS GET距离,返回0,当我再次preSS它的应用说:不幸的是应用程序已停止。也许这是因为它没有达到运行?当我的线程T1 =新主题(新MainActivity());,它,当我preSS开始移动坠毁。现在它是T1 =新的Thread(),但距离为0而坠毁。这两个方案均未达到Run方法。
所有的距离变成0,所以我想这是因为我的LAT2值为空当它在运行方法首先计算出,成为1纬度前值..所以我首先赋予它一个值,当我开始移动。结果
同时,我怎么停止计时,使DIST 0当我第一次preSS重新开始?时间不会停止,即使我pressed站。基本上,我的问题是,如何使其运行方式运行,当线程启动停车时,停止计时和线程。
曾几何时,距离没出事前一段时间,但没有积累(如图不是codeS)我测试停止定时器但时间仍然继续。还使用Thread.stop似乎危险的,因为很多地方建议。做我只是让DIS = 0?我使用布尔从积累停止距离或重新开始。所以我需要停止线程?

修改:这是更新codeS

公共类MainActivity扩展活动实现Runnable {

 私有静态最后长MINIMUM_DISTANCE_CHANGE_FOR_UPDATES = 1; //在米
    私有静态最后长MINIMUM_TIME_BETWEEN_UPDATES = 30000;    受保护的LocationManager的LocationManager;
    静态双N = 0;
    龙S1,R1;
    双LAT1,lon1,lat3,lon3,LAT2,lon2;
    双DIS = 0.0;
    mycount的计数器;
    螺纹T1;
    E1的EditText;
    布尔布尔= TRUE;
    诠释计数= 0;按钮btnCurrentPosition,btnStartMove,btnPause,btnResume,btnStop,btnGetDistance;
/ **当第一次创建活动调用。 * /@覆盖
保护无效的onCreate(捆绑savedInstanceState){
    super.onCreate(savedInstanceState);
    的setContentView(R.layout.activity_main);
    btnCurrentPosition =(按钮)findViewById(R.id.C​​urrentPosition); //当前位置
    btnStartMove =(按钮)findViewById(R.id.StartMove); //开始移动..计算上点击这个距离
    btnP​​ause =(按钮)findViewById(R.id.Pause); //暂停
    btnResume =(按钮)findViewById(R.id.Resume); //简历
    btnStop =(按钮)findViewById(R.id.Stopping);
    btnGetDistance =(按钮)findViewById(R.id.GetDistance); //获取距离
    E1 =(EditText上)findViewById(R.id.Text1);
    的LocationManager =(的LocationManager)getSystemService(Context.LOCATION_SERVICE);
    locationManager.requestLocationUpdates(
            LocationManager.GPS_PROVIDER,
            MINIMUM_TIME_BETWEEN_UPDATES,
            MINIMUM_DISTANCE_CHANGE_FOR_UPDATES,
            新MyLocationListener()
    );
    btnCurrentPosition.setOnClickListener(新OnClickListener()
    {
        @覆盖
        公共无效的onClick(视图v){
            showCurrentLocation();
        }
    });
    btnStartMove.setOnClickListener(新OnClickListener()
    {
        @覆盖
        公共无效的onClick(视图v){
            星空卫视);
        }
    });
    btnP​​ause.setOnClickListener(新OnClickListener()
    {
        @覆盖
        公共无效的onClick(视图v){
            // TODO自动生成方法存根
            星空卫视);
        }
    });
    btnResume.setOnClickListener(新OnClickListener()
    {
        @覆盖
        公共无效的onClick(视图v){
            // TODO自动生成方法存根
            星空卫视);
        }
    });
    btnStop.setOnClickListener(新OnClickListener()
    {
        @覆盖
        公共无效的onClick(视图v){
            // TODO自动生成方法存根
            星空卫视);
        }
    });
    btnGetDistance.setOnClickListener(新OnClickListener()
    {
        @覆盖
        公共无效的onClick(视图v){
            // TODO自动生成方法存根
            星空卫视);
        }
    });}保护无效showCurrentLocation()
{
    地点= locationManager.getLastKnownLocation(LocationManager.GPS_PROVIDER);    如果(位置!= NULL){
        字符串消息=的String.format(
                当前位置\\ n经度:%1 $ S \\北纬:%2 $ S
                location.getLongitude(),location.getLatitude()
        );
        LAT1 = location.getLatitude();
        lon1 = location.getLongitude();
        Toast.makeText(MainActivity.this,消息,
                Toast.LENGTH_LONG).show();
        Toast.makeText(MainActivity.this,在米的距离:+将String.valueOf(DIS),Toast.LENGTH_LONG).show();
        Toast.makeText(MainActivity.this,伯爵的价值:+将String.valueOf(计数)
                Toast.LENGTH_LONG).show();
    }
    其他{
        Toast.makeText(MainActivity.this,空位置
                Toast.LENGTH_LONG).show();
    }
}公共无效启动(视图v){    开关(v.getId()){    案例R.id.StartMove:
        地点= locationManager.getLastKnownLocation(LocationManager.GPS_PROVIDER);
        LAT2 = location.getLatitude();
        lon2 = location.getLongitude();
        布尔= TRUE;
        T1 =新主题(本);
        t1.start();
        //线程t =新主题(新MainActivity()); t.start()
        //新MainActivity()
        计数器=新mycount的(30000,1000);
     counter.start();
     打破;
    案例R.id.Pause:
        counter.cancel();
        布尔= FALSE;
        打破;
    案例R.id.Resume:
        计数器=新mycount的(s1,1000);
     counter.start();
     布尔= TRUE;
     打破;
    案例R.id.GetDistance:        Toast.makeText(MainActivity.this,达到获得距离,
                Toast.LENGTH_LONG).show();
        //跑();
        双倍时间= N * 30 + R1;        Toast.makeText(MainActivity.this,距离米:+将String.valueOf(DIS)+速度米/秒:+将String.valueOf(DIS /时间)+时间:+将String.valueOf(时间),Toast.LENGTH_LONG).show();    案例R.id.Stopping:
        counter.cancel();
        计数器= NULL;
        布尔= FALSE;        // R1 =(长)0;    }
}私有类MyLocationListener实现LocationListener的{    公共无效onLocationChanged(地点){
        字符串消息=的String.format(
                新位置\\ n经度:%1 $ S \\北纬:%2 $ S
                location.getLongitude(),location.getLatitude()
        );
        Toast.makeText(MainActivity.this,消息,Toast.LENGTH_LONG).show();
    }    公共无效onStatusChanged(字符串s INT I,叠B){
        Toast.makeText(MainActivity.this,供应商的地位变化,
                Toast.LENGTH_LONG).show();
    }    公共无效onProviderDisabled(String s)将{
        Toast.makeText(MainActivity.this,
                用户。GPS禁用提供商关闭,
                Toast.LENGTH_LONG).show();
    }    公共无效onProviderEnabled(String s)将{
        Toast.makeText(MainActivity.this,
                由用户。启用GPS提供商接通,
                Toast.LENGTH_LONG).show();
    }}公共类mycount的扩展CountDownTimer {
    公共mycount的(长millisInFuture,长countDownInterval){
    超(mil​​lisInFuture,countDownInterval);
    }
    @覆盖
    公共无效onFinish(){
        计数器=新mycount的(30000,1000);
     counter.start();
     N = N + 1;
    }
    @覆盖
    公共无效onTick(长millisUntilFinished){
        S1 = millisUntilFinished;
        R1 =(30000-S1)/ 1000;
        e1.setText(将String.valueOf(R1));
    }
}@覆盖
公共无效的run()
{
    数= 6;
    地点= locationManager.getLastKnownLocation(LocationManager.GPS_PROVIDER);
    而(布尔==真)
    {
        LAT1 = location.getLatitude();
        lon1 = location.getLongitude();        如果(LAT1!= || LAT2 lon1!= lon2)
        {
            DIS + = getDistance的(LAT2,lon2,LAT1,lon1);
            LAT2 = LAT1;
            lon2 = lon1;
            数= 7;
        }    }}公共双getDistance的(双LAT1,双lon1,双LAT2,双lon2){
    双拉塔= Math.toRadians(LAT1);
    双LONA = Math.toRadians(lon1);
    双LATB = Math.toRadians(LAT2);
    双lonB = Math.toRadians(lon2);
    双cosAng =(Math.cos(阔)* Math.cos(LATB)* Math.cos(lonB-LONA))+
                    (Math.sin(阔)* Math.sin(LATB));
    双ANG = Math.acos(cosAng);
    双DIST =昂* 6371;
    返回DIST;
}

编辑:上述更新codes为我使用另一种方法,以确定它是否有达到运行()。我试图显示的距离并计算在getCurrentPosition,而不是它的目的,只是为了测试codeS。的距离出现,只是该值保持相同。计数值为7,所以证明它达到我的方法运行。然后我点击getDistance的,距离值结果都保持位置更新一样的,但是当我再次单击它,它崩溃。我不知道我的距离按钮的问题。我点击它第一次显示,wherther值是准确或不准确。第二次,它甚至没有显示到达的距离得到。屏幕挂1秒钟,然后坠毁。我甚至创建具有相同codeS和运行另一个项目。其结果是,当我第一次运行它,它显示应用程序之前崩溃。
我无论是在Android和这里,如果我做错了什么,请告诉我一个新的用户。谢谢。我不知道如果我的问题是太一般了。

这是坠毁时,它第一次运行。

项目的LogCat中

  01-21 22:13:05.950:D / dalvikvm(911):不晚启用CheckJNI(已上)
01-21 22:13:09.240:D / AndroidRuntime(911):关闭VM
01-21 22:13:09.250:W / dalvikvm(911):主题ID = 1:螺纹未捕获的异常退出(组= 0xb3a2cb90)
01-21 22:13:09.320:E / AndroidRuntime(911):致命异常:主要
01-21 22:13:09.320:E / AndroidRuntime(911):工艺:com.example.gpsdistance,PID:911
01-21 22:13:09.320:E / AndroidRuntime(911):了java.lang.RuntimeException:无法启动活动ComponentInfo {com.example.gpsdistance / com.example.gpsdistance.MainActivity}:java.lang.SecurityException异常: GPS定位提供商要求ACCESS_FINE_LOCATION许可。
01-21 22:13:09.320:E / AndroidRuntime(911):在android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2176)
01-21 22:13:09.320:E / AndroidRuntime(911):在android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2226)
01-21 22:13:09.320:E / AndroidRuntime(911):在android.app.ActivityThread.access $ 700(ActivityThread.java:135)
01-21 22:13:09.320:E / AndroidRuntime(911):在android.app.ActivityThread $ H.handleMessage(ActivityThread.java:1397)
01-21 22:13:09.320:E / AndroidRuntime(911):在android.os.Handler.dispatchMessage(Handler.java:102)
01-21 22:13:09.320:E / AndroidRuntime(911):在android.os.Looper.loop(Looper.java:137)
01-21 22:13:09.320:E / AndroidRuntime(911):在android.app.ActivityThread.main(ActivityThread.java:4998)
01-21 22:13:09.320:E / AndroidRuntime(911):在java.lang.reflect.Method.invokeNative(本机方法)
01-21 22:13:09.320:E / AndroidRuntime(911):在java.lang.reflect.Method.invoke(Method.java:515)
01-21 22:13:09.320:E / AndroidRuntime(911):在com.android.internal.os.ZygoteInit $ MethodAndArgsCaller.run(ZygoteInit.java:777)
01-21 22:13:09.320:E / AndroidRuntime(911):在com.android.internal.os.ZygoteInit.main(ZygoteInit.java:593)
01-21 22:13:09.320:E / AndroidRuntime(911):在dalvik.system.NativeStart.main(本机方法)
01-21 22:13:09.320:E / AndroidRuntime(911):java.lang.SecurityException异常:产生的原因GPS定位提供商要求ACCESS_FINE_LOCATION许可。
01-21 22:13:09.320:E / AndroidRuntime(911):在android.os.Parcel.readException(Parcel.java:1461)
01-21 22:13:09.320:E / AndroidRuntime(911):在android.os.Parcel.readException(Parcel.java:1415)
01-21 22:13:09.320:E / AndroidRuntime(911):在android.location.ILocationManager $存根$ Proxy.requestLocationUpdates(ILocationManager.java:540)
01-21 22:13:09.320:E / AndroidRuntime(911):在android.location.LocationManager.requestLocationUpdates(LocationManager.java:860)
01-21 22:13:09.320:E / AndroidRuntime(911):在android.location.LocationManager.requestLocationUpdates(LocationManager.java:454)
01-21 22:13:09.320:E / AndroidRuntime(911):在com.example.gpsdistance.MainActivity.onCreate(MainActivity.java:53)
01-21 22:13:09.320:E / AndroidRuntime(911):在android.app.Activity.performCreate(Activity.java:5243)
01-21 22:13:09.320:E / AndroidRuntime(911):在android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
01-21 22:13:09.320:E / AndroidRuntime(911):在android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2140)
01-21 22:13:09.320:E / AndroidRuntime(911):11 ...更多


解决方案

添加权限

 <使用许可权的android:NAME =android.permission.ACCESS_FINE_LOCATION/>

任何问题,让我通知或进行再+1

i am still working on a project i have asked a question on here. it is to calculate the accumulated distance a person has traveled or run after a time. i do not know whether i should start a new question or continuing from the first one i asked first since i progress a lot since then and my codes are a lot of different with different errors. i tried to use the debugger in eclipse but it did not work and i don't understand it. the distance accumulating part is what was troubling me and i use the Runnable run method. but my application did not reach the Run method when it crashed. when i press start move, it display "Second value succeeded"and "Thread started", this is just to show me that it reach that point. but it did not display "Run is running" so it never reach the run method. when i test the codes, i enter location data using a emulator. does it have any different effect when it is real time? i always thought it is impossible to use real time when developing codes in the laptop. if there is, could someone tell me? from the research, all people I've seen use emulator. i a new user and so do not understand how to use the debugger, i tried it but it did not show anything.

when i press get distance, return 0, and when i press again it the app say "unfortunately "app" has stopped". maybe it is because it did not reach Run? when my thread was t1=new Thread(new MainActivity());, it crashed when i press start moving. right now it is t1=new Thread() but the distance is 0 and crashed. both scenario did not reach the Run method. all distance turn out 0, so i thought it is because my lat2 value was null when it first calculated in the Run method, before becoming lat 1 value.. so i assigned it a value first when i start moving.
also, how do i stop the timer and make dist 0 when i first press start again? the time won't stop even if i pressed stop. basically, my problem is, how do it make the Run method run when thread is started when stopping, stop the timer and thread. there was a time before when distance did not crash, but not accumulated(not the codes shown) i tested to stop the timer but the time still goes on. also Thread.Stop seem dangerous as many places suggest. do i just make the dis=0? i use bool to stop the distance from accumulating or to start again. so do i need to stop the thread?

EDIT: this is the updated codes.

public class MainActivity extends Activity implements Runnable{

 private static final long MINIMUM_DISTANCE_CHANGE_FOR_UPDATES = 1; // in Meters
    private static final long MINIMUM_TIME_BETWEEN_UPDATES = 30000;

    protected LocationManager locationManager;
    static double n=0;
    Long s1,r1;
    double lat1,lon1,lat3,lon3,lat2,lon2;
    double dis=0.0;
    MyCount counter;
    Thread t1;
    EditText e1;
    boolean bool=true;
    int count=0;

Button btnCurrentPosition,btnStartMove,btnPause,btnResume,btnStop,btnGetDistance;
/** Called when the activity is first created. */

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);     
    btnCurrentPosition=(Button)findViewById(R.id.CurrentPosition);//current position
    btnStartMove=(Button)findViewById(R.id.StartMove);//start moving.. calculates distance on clicking this
    btnPause=(Button)findViewById(R.id.Pause);//pause
    btnResume=(Button)findViewById(R.id.Resume);//resume
    btnStop=(Button)findViewById(R.id.Stopping);
    btnGetDistance=(Button)findViewById(R.id.GetDistance);//get distance
    e1=(EditText)findViewById(R.id.Text1);
    locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
    locationManager.requestLocationUpdates(
            LocationManager.GPS_PROVIDER, 
            MINIMUM_TIME_BETWEEN_UPDATES, 
            MINIMUM_DISTANCE_CHANGE_FOR_UPDATES,
            new MyLocationListener()
    );
    btnCurrentPosition.setOnClickListener(new OnClickListener() 
    {
        @Override
        public void onClick(View v) {
            showCurrentLocation();
        }
    });  
    btnStartMove.setOnClickListener(new OnClickListener() 
    {
        @Override
        public void onClick(View v) {
            start(v);
        }
    });
    btnPause.setOnClickListener(new OnClickListener() 
    {
        @Override
        public void onClick(View v) {
            // TODO Auto-generated method stub
            start(v); 
        }
    });
    btnResume.setOnClickListener(new OnClickListener() 
    {
        @Override
        public void onClick(View v) {
            // TODO Auto-generated method stub
            start(v); 
        }
    });
    btnStop.setOnClickListener(new OnClickListener() 
    {
        @Override
        public void onClick(View v) {
            // TODO Auto-generated method stub
            start(v); 
        }
    });
    btnGetDistance.setOnClickListener(new OnClickListener() 
    {
        @Override
        public void onClick(View v) {
            // TODO Auto-generated method stub
            start(v);
        }
    });

}

protected void showCurrentLocation() 
{
    Location location = locationManager.getLastKnownLocation(LocationManager.GPS_PROVIDER);

    if (location != null) {
        String message = String.format(
                "Current Location \n Longitude: %1$s \n Latitude: %2$s",
                location.getLongitude(), location.getLatitude()
        );
        lat1=location.getLatitude();
        lon1=location.getLongitude();
        Toast.makeText(MainActivity.this, message,
                Toast.LENGTH_LONG).show();
        Toast.makeText(MainActivity.this,"distance in metres:"+String.valueOf(dis),Toast.LENGTH_LONG).show();
        Toast.makeText(MainActivity.this, "Value of Count:" + String.valueOf(count),
                Toast.LENGTH_LONG).show();
    }
    else{
        Toast.makeText(MainActivity.this, "null location",
                Toast.LENGTH_LONG).show();
    }


}

public void start (View v){

    switch(v.getId()){

    case R.id.StartMove:
        Location location = locationManager.getLastKnownLocation(LocationManager.GPS_PROVIDER);
        lat2=location.getLatitude();
        lon2=location.getLongitude();
        bool=true;
        t1=new Thread(this);
        t1.start();
        //  Thread t = new Thread(new MainActivity()); t.start()
        //new MainActivity()
        counter= new MyCount(30000,1000);
     counter.start();
     break;
    case R.id.Pause:
        counter.cancel();
        bool=false;
        break;
    case R.id.Resume:
        counter= new MyCount(s1,1000);
     counter.start();
     bool=true;
     break;
    case R.id.GetDistance:

        Toast.makeText(MainActivity.this, "reach get distance",
                Toast.LENGTH_LONG).show();
        //run();
        double time=n*30+r1;

        Toast.makeText(MainActivity.this,"distance in metres:"+String.valueOf(dis)+"Velocity in m/sec :"+String.valueOf(dis/time)+"Time :"+String.valueOf(time),Toast.LENGTH_LONG).show();

    case R.id.Stopping:
        counter.cancel();
        counter = null;
        bool = false;

        //r1 = (long) 0;

    }
}

private class MyLocationListener implements LocationListener {

    public void onLocationChanged(Location location) {
        String message = String.format(
                "New Location \n Longitude: %1$s \n Latitude: %2$s",
                location.getLongitude(), location.getLatitude()
        );
        Toast.makeText(MainActivity.this, message, Toast.LENGTH_LONG).show();
    }

    public void onStatusChanged(String s, int i, Bundle b) {
        Toast.makeText(MainActivity.this, "Provider status changed",
                Toast.LENGTH_LONG).show();
    }

    public void onProviderDisabled(String s) {
        Toast.makeText(MainActivity.this,
                "Provider disabled by the user. GPS turned off",
                Toast.LENGTH_LONG).show();
    }

    public void onProviderEnabled(String s) {
        Toast.makeText(MainActivity.this,
                "Provider enabled by the user. GPS turned on",
                Toast.LENGTH_LONG).show();
    }

}

public class MyCount extends CountDownTimer{
    public MyCount(long millisInFuture, long countDownInterval) {
    super(millisInFuture, countDownInterval);
    }
    @Override
    public void onFinish() {
        counter= new MyCount(30000,1000);
     counter.start();
     n=n+1;
    }
    @Override
    public void onTick(long millisUntilFinished) {
        s1=millisUntilFinished;
        r1=(30000-s1)/1000;
        e1.setText(String.valueOf(r1));


    }
}

@Override
public void run() 
{
    count=6;
    Location location = locationManager.getLastKnownLocation(LocationManager.GPS_PROVIDER);
    while(bool==true)
    {
        lat1=location.getLatitude();
        lon1=location.getLongitude();

        if(lat1!=lat2 || lon1!=lon2)
        {
            dis+=getDistance(lat2,lon2,lat1,lon1);
            lat2=lat1;
            lon2=lon1;
            count=7;
        }

    }

}

public double getDistance(double lat1, double lon1, double lat2, double lon2) {
    double latA = Math.toRadians(lat1);
    double lonA = Math.toRadians(lon1);
    double latB = Math.toRadians(lat2);
    double lonB = Math.toRadians(lon2);
    double cosAng = (Math.cos(latA) * Math.cos(latB) * Math.cos(lonB-lonA)) +
                    (Math.sin(latA) * Math.sin(latB));
    double ang = Math.acos(cosAng);
    double dist = ang *6371;
    return dist;
}

EDIT: the above updated codes is i use another method to determine whether it has reach the Run(). i tried to display the distance and count in the getCurrentPosition, not its purpose, just to test the codes. the distance appear,just that the value remains the same. the count value is 7, so it prove that it reach my Run method. i then click GetDistance, distance value result remains the same even when the location is updated, but when i click it again, it crash. i don't know the problem with my distance button. i click the first time, it display, wherther value is accurate or inaccurate. the second time, it did not even display "reach get distance". the screen hang for 1 second then it crashed. i even create another project with the same codes and run. the result is when i first run it, it crashed before displaying the application. i a new user both in android and here so if i done anything wrong, please tell me. thanks. I'm not sure if my question is too general.

this is the LogCat of the project that crashed when it first run.

01-21 22:13:05.950: D/dalvikvm(911): Not late-enabling CheckJNI (already on)
01-21 22:13:09.240: D/AndroidRuntime(911): Shutting down VM
01-21 22:13:09.250: W/dalvikvm(911): threadid=1: thread exiting with uncaught exception (group=0xb3a2cb90)
01-21 22:13:09.320: E/AndroidRuntime(911): FATAL EXCEPTION: main
01-21 22:13:09.320: E/AndroidRuntime(911): Process: com.example.gpsdistance, PID: 911
01-21 22:13:09.320: E/AndroidRuntime(911): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.gpsdistance/com.example.gpsdistance.MainActivity}: java.lang.SecurityException: "gps" location provider requires ACCESS_FINE_LOCATION permission.
01-21 22:13:09.320: E/AndroidRuntime(911):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2176)
01-21 22:13:09.320: E/AndroidRuntime(911):  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2226)
01-21 22:13:09.320: E/AndroidRuntime(911):  at android.app.ActivityThread.access$700(ActivityThread.java:135)
01-21 22:13:09.320: E/AndroidRuntime(911):  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1397)
01-21 22:13:09.320: E/AndroidRuntime(911):  at android.os.Handler.dispatchMessage(Handler.java:102)
01-21 22:13:09.320: E/AndroidRuntime(911):  at android.os.Looper.loop(Looper.java:137)
01-21 22:13:09.320: E/AndroidRuntime(911):  at android.app.ActivityThread.main(ActivityThread.java:4998)
01-21 22:13:09.320: E/AndroidRuntime(911):  at java.lang.reflect.Method.invokeNative(Native Method)
01-21 22:13:09.320: E/AndroidRuntime(911):  at java.lang.reflect.Method.invoke(Method.java:515)
01-21 22:13:09.320: E/AndroidRuntime(911):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:777)
01-21 22:13:09.320: E/AndroidRuntime(911):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:593)
01-21 22:13:09.320: E/AndroidRuntime(911):  at dalvik.system.NativeStart.main(Native Method)
01-21 22:13:09.320: E/AndroidRuntime(911): Caused by: java.lang.SecurityException: "gps" location provider requires ACCESS_FINE_LOCATION permission.
01-21 22:13:09.320: E/AndroidRuntime(911):  at android.os.Parcel.readException(Parcel.java:1461)
01-21 22:13:09.320: E/AndroidRuntime(911):  at android.os.Parcel.readException(Parcel.java:1415)
01-21 22:13:09.320: E/AndroidRuntime(911):  at android.location.ILocationManager$Stub$Proxy.requestLocationUpdates(ILocationManager.java:540)
01-21 22:13:09.320: E/AndroidRuntime(911):  at android.location.LocationManager.requestLocationUpdates(LocationManager.java:860)
01-21 22:13:09.320: E/AndroidRuntime(911):  at android.location.LocationManager.requestLocationUpdates(LocationManager.java:454)
01-21 22:13:09.320: E/AndroidRuntime(911):  at com.example.gpsdistance.MainActivity.onCreate(MainActivity.java:53)
01-21 22:13:09.320: E/AndroidRuntime(911):  at android.app.Activity.performCreate(Activity.java:5243)
01-21 22:13:09.320: E/AndroidRuntime(911):  at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
01-21 22:13:09.320: E/AndroidRuntime(911):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2140)
01-21 22:13:09.320: E/AndroidRuntime(911):  ... 11 more

解决方案

add permission

  <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />

any problem let me inform or done then +1

这篇关于计算使用GPS累积的距离(不能调用run方法)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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