Geolocation coordinate format in Android

private String formatLocation(Location location) {
    if (location == null)
        return "";
    return String.format(
            "Coordinates: lat = \n%1$.6f\n, lon = \n%2$.6f\n, time = \n%3$tF %3$tT",
            location.getLatitude(), location.getLongitude(), new Date(
                    location.getTime()));
}

BUT:

If the phone language is Russian, the coordinates come in the style of "53.66678" (comma).)

And in English.phone number "53.66678" (dot)

The application is still working with coordinates and this element (dot/comma) is one of the key ones.

How do I bring geolocation data to the same view regardless of the device language?

Author: Wlad, 2019-02-09

1 answers

Try this way:

return String.format(
            Locale.US,
            "Coordinates: lat = \n%1$.6f\n, lon = \n%2$.6f\n, time = \n%3$tF %3$tT",
            location.getLatitude(), location.getLongitude(), new Date(
                    location.getTime()));

Or so:

Locale locale = new Locale("en_US");
return String.format(
            locale,
            "Coordinates: lat = \n%1$.6f\n, lon = \n%2$.6f\n, time = \n%3$tF %3$tT",
            location.getLatitude(), location.getLongitude(), new Date(
                    location.getTime()));
 1
Author: virex-84, 2019-02-11 04:39:34