【问题标题】:Convert location units from miles to meters Android [closed]将位置单位从英里转换为米 Android [关闭]
【发布时间】:2018-04-06 18:57:09
【问题描述】:

我想把英里换算成米?和其他单位公制? 我尝试了许多变体来改变值,但它没有帮助我,请有人可以做到吗?如果有必要,我可以分享我所有的代码,是的,对不起我的英语。

有我的代码请帮忙。

Double speedInMilesPerHour = location.getSpeed()* 3.6; //inMeters
    requestParams.put("speed",  Integer.toString(speedInMilesPerHour.intValue()));

    try {
        requestParams.put("date", URLEncoder.encode(dateFormat.format(date), "UTF-8"));
    } catch (UnsupportedEncodingException e) {}

    requestParams.put("locationmethod", location.getProvider());

    if (totalDistanceInMeters > 0) {
        requestParams.put("distance", String.format("%.1f", totalDistanceInMeters / 1609)); // in miles,
    } else {
        requestParams.put("distance", "0.0"); // in miles
    }

    requestParams.put("username", sharedPreferences.getString("userName", ""));
    requestParams.put("phonenumber", sharedPreferences.getString("appID", "")); // uuid
    requestParams.put("sessionid", sharedPreferences.getString("sessionID", "")); // uuid

    Double accuracyInFeet = location.getAccuracy()* 3.28;
    requestParams.put("accuracy",  Integer.toString(accuracyInFeet.intValue()));

    Double altitudeInFeet = location.getAltitude() * 3.28;
    requestParams.put("extrainfo",  Integer.toString(altitudeInFeet.intValue()));

【问题讨论】:

  • 用谷歌搜索miles to meter
  • 但是如何例如 Double accuracyInFeet = location.getAccuracy()* 3.28;这个我可以转换吗?

标签: java android gps location metrics


【解决方案1】:

你可以编写简单的转换方法来处理双精度:

    public static final double METERS_IN_MILE = 1609.344;

    public static double metersToMiles(double meters) {
        return meters / METERS_IN_MILE;
    }
    
    public static double milesToMeters(double miles) {
        return miles * METERS_IN_MILE;
    }

【讨论】:

  • milesToMeters 公式中的错误。应该是miles / 0.0006213711
  • 据我所知 1 英里 = 1609.344 米。我不确定你的 1609.3440057765 来自哪里? en.wikipedia.org/wiki/…
猜你喜欢
  • 2014-01-07
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2020-07-28
  • 2020-01-30
相关资源
最近更新 更多