1

i try to get distance between two Positions and tried the following code:

Location startPoint=new Location("locationA");
    startPoint.setLatitude(17.372102);
    startPoint.setLongitude(78.484196);

    Location endPoint=new Location("locationA");
    endPoint.setLatitude(17.375775);
    endPoint.setLongitude(78.469218);

    double distance= (int) startPoint.distanceTo(endPoint);
    TextView dis = (TextView) findViewById(R.id.distance);
  dis.setText((int) distance);

unfortunately my app is crashing always if i try to calculate the distance between this two points

Dominik Hartl
  • 101
  • 11

1 Answers1

0

Here is the problem in your code

 TextView dis = (TextView) findViewById(R.id.distance);
 dis.setText((int) distance);

setText() method expects string and you are setting int. Convert distance to string. You can do as

1) dis.setText(String.valueOf(distance));

OR

2)dis.setText("" +distance);

hope this helps

Abdul Waheed
  • 4,540
  • 6
  • 35
  • 58