Отображение расстояния с расстояния до - PullRequest
0 голосов
/ 26 мая 2018

Во-первых, извините за мой плохой английский.Я не могу отобразить пройденное расстояние в своем телефоне, это мой код, и я не могу найти ошибку.Я думаю, что это могут быть разрешения

Location mCurrentLocation, lStart, lEnd;
float dist=0;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    LocationManager lm = (LocationManager) this.getSystemService(Context.LOCATION_SERVICE);
    if (ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {

        return;
    }
    lm.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, this);

    this.onLocationChanged(null);
}

public void onLocationChanged(Location location) {
        mCurrentLocation=location;
    if(lStart==null){
        lStart=lEnd=mCurrentLocation;
    }else{
        lEnd=mCurrentLocation;
    }
    updateUI();
}

private void updateUI(){
    TextView txt2 = (TextView) this.findViewById(R.id.textView2);
        dist = dist + (lStart.distanceTo(lEnd));
        txt2.setText(dist + "m");
        lStart = lEnd;
}
...