Android: how to find total distance covered using GPS when continuously moving?

泪湿孤枕 提交于 2019-12-04 14:06:50

The problem that you are defining an empty location Location loc2=new Location(""); and then using it.

You can define lat1 and lon1 in your class.

public void onLocationChanged(Location loc1) 
{

    if(lat1 != 0 && long1 != 0) { 
       Location.distanceBetween(lat1,lon1,loc1.getLatitude(),loc1.getLongitude(),dist);
       res+=(long)dist[0];
    }

    lat1=loc1.getLatitude();
    lon1=loc1.getLongitude();
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!