Guest User

Untitled

a guest
May 26th, 2018
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.08 KB | None | 0 0
  1. Location mCurrentLocation, lStart, lEnd;
  2. float dist=0;
  3.  
  4. @Override
  5. protected void onCreate(Bundle savedInstanceState) {
  6. super.onCreate(savedInstanceState);
  7. setContentView(R.layout.activity_main);
  8.  
  9. LocationManager lm = (LocationManager) this.getSystemService(Context.LOCATION_SERVICE);
  10. if (ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
  11.  
  12. return;
  13. }
  14. lm.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, this);
  15.  
  16. this.onLocationChanged(null);
  17. }
  18.  
  19. public void onLocationChanged(Location location) {
  20. mCurrentLocation=location;
  21. if(lStart==null){
  22. lStart=lEnd=mCurrentLocation;
  23. }else{
  24. lEnd=mCurrentLocation;
  25. }
  26. updateUI();
  27. }
  28.  
  29. private void updateUI(){
  30. TextView txt2 = (TextView) this.findViewById(R.id.textView2);
  31. dist = dist + (lStart.distanceTo(lEnd));
  32. txt2.setText(dist + "m");
  33. lStart = lEnd;
  34. }
Add Comment
Please, Sign In to add comment