Search code examples
filemaker

FileMaker calculation to convert DMS latlong to decimal format


I need a FileMaker "calculation" script to convert a DMS latlong (eg: 37°55'43.6"S, 145°11'26.1"E) to a decimal format (eg: -37.928778,145.190583).


Solution

  • Here's a fun way to do it: convert it to a FileMaker calculation and call Evaluate() on it.

    Evaluate( 
      "Round(  (" &
      Substitute ( 
        dms ; 
        [" ";""] ; 
        ["°";" + "] ; 
        ["'";"/60 + "] ; 
        ["\"";"/3600"] ; 
        ["S";") *-1"] ; 
        ["W";") *-1"] ; 
        ["N";")"] ; 
        ["E";")"] ; 
        [","; " ; 6 ) & \",\" & Round( ("]
      ) & 
      " ; 6 )"
    )
    

    The above will turn the input into a calc like:

    Round( (37 + 55/60 + 43.6/3600) *-1 ; 6 ) & "," & Round( (145 + 11/60 + 26.1/3600) ; 6 )
    

    then passes that to Evaluate, which gives you -37.928778,145.190583