i want to convert miles to meters? and other units to metric? I tried many variants to change values but its didn’t help me,please someone can do it? if it’s neccessary i can share all my code, and yes sorry for my English.
There is my code please help.
JavaScript
x
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()));
Advertisement
Answer
You could just write simple conversion methods that work with doubles:
JavaScript
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;
}