如何找到两个经度位置之间的距离?

时间:2016-03-29 04:28:19

标签: android

我希望你帮助计算两个经度的距离b / t。谁能告诉我如何找到距离?我是Android工作室的新手。我想在我的应用中找到距离。由mlatmlong定义的目标地址和当前地址是通过GPS计算的,其值在经度和纬度上。

我的代码是:

    double mlat =30.726030;
    double mlong=76.759268;
    imgButton1 =(ImageButton)findViewById(R.id.imageButton1);
    mgButton1.setOnClickListener(new View.OnClickListener() {
          @Override
          public void onClick(View v) {
                Location gpsLocation = appLocationService.getLocation(LocationManager.GPS_PROVIDER);
                if (gpsLocation != null) {
                     double latitude = gpsLocation.getLatitude();
                     double longitude = gpsLocation.getLongitude();    
                     String result = "Latitude: " + gpsLocation.getLatitude() +
                                    " Longitude: " + gpsLocation.getLongitude();
                     tvAddress.setText(result);
                } else {
                     showSettingsAlert();
                }
          }
   });

告诉我如何找到两个经度和纬度之间的距离。

3 个答案:

答案 0 :(得分:0)

尝试下面

Location loc1 = new Location("");
loc1.setLatitude(lat1);
loc1.setLongitude(lon1);

Location loc2 = new Location("");
loc2.setLatitude(lat2);
loc2.setLongitude(lon2);

float distanceInMeters = loc1.distanceTo(loc2);

答案 1 :(得分:0)

这是简单的坐标数学。或者你可以使用found by googling这种方法。

答案 2 :(得分:0)

使用distanceBetween方法计算距离:

Location.distanceBetween(double startLatitude, double startLongitude, double endLatitude, double endLongitude, float[] results)
相关问题