Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 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;
- }
Add Comment
Please, Sign In to add comment