Android 如何计算两个坐标之间的距离

Android 如何计算两个坐标之间的距离,android,google-maps,distance,Android,Google Maps,Distance,我尝试获取两个位置之间的距离,并尝试了以下代码: Location startPoint=new Location("locationA"); startPoint.setLatitude(17.372102); startPoint.setLongitude(78.484196); Location endPoint=new Location("locationA"); endPoint.setLatitude(17.375775); endPoint

我尝试获取两个位置之间的距离,并尝试了以下代码:

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);

不幸的是,如果我试图计算这两点之间的距离,我的应用程序总是会崩溃

 TextView dis = (TextView) findViewById(R.id.distance);
 dis.setText((int) distance);
setText()方法需要字符串,您正在设置int。请将距离转换为字符串。你可以随心所欲

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

2) dis.setText(“+”距离)


希望这有帮助

这是代码中的问题

 TextView dis = (TextView) findViewById(R.id.distance);
 dis.setText((int) distance);
setText()方法需要字符串,您正在设置int。请将距离转换为字符串。你可以随心所欲

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

2) dis.setText(“+”距离)


希望这有助于使用
dis.setText(String.valueOf((int)distance))重复的。您是否尝试使用
haversine公式
?使用
dis.setText(String.valueOf((int)distance))的副本。您是否尝试过使用
haversine公式
?我很高兴我提供了帮助。我很高兴我提供了帮助。