Search code examples
javaandroiddecimallatitude-longitudeapproximation

Number of decimal digits in converted latitude/longitude values (with Location.convert method)


I am trying to create a converter utility for latitude/longitude coordinates.

Please look at this code snippet:

    ...
    //at this point the location variable has valid location information

    String latDegrees = Location.convert(location.getLatitude(), Location.FORMAT_DEGREES);
    String longDegrees = Location.convert(location.getLongitude(), Location.FORMAT_DEGREES);

    String latMinutes = Location.convert(location.getLatitude(), Location.FORMAT_MINUTES);
    String longMinutes = Location.convert(location.getLongitude(), Location.FORMAT_MINUTES);

    String latSeconds = Location.convert(location.getLatitude(), Location.FORMAT_SECONDS);
    String longSeconds = Location.convert(location.getLongitude(), Location.FORMAT_SECONDS);


    Log.d("results ","lat "+location.getLatitude());
    Log.d("results ","long "+location.getLongitude());
    Log.d("results ","lat degrees "+latDegrees);
    Log.d("results ","long degrees "+longDegrees);
    Log.d("results ","lat min "+latMinutes);
    Log.d("results ","long min "+longMinutes);
    Log.d("results ","lat sec "+latSeconds);
    Log.d("results ","long sec "+longSeconds);
    ...

I get this kind of strings

results: lat aa.4919783
results: long bb.3432917
results: lat degrees aa.49198
results: long degrees bb.34329
results: lat min aa:29.5187
results: long min bb:20.5975
results: lat sec aa:29:31.12188
results: long sec bb:20:35.85012

(where I concealed the first two digits with letters)

As you can see,

-the original values have 7 decimal digits

-the degrees have 5

-the minutes have 4

-the seconds have 5

Is it correct? Can those strings be used where latitude and longitude are needed as a parameter? Is that a standard form, or other decimals could be necessary?


Solution

  • According to documentation, all converted results have 5 decimal digit max. If decimal end with one or several 0 digit, they will be ignored, so converted results can have less than 5 decimal digit.

    The original value is a Double, so it doesn't have fixed decimal digits