= 8) { $decimalPart = substr($decimalPart, 0, 8); } else { $decimalPart = str_pad($decimalPart, 8, '0', STR_PAD_RIGHT); } // concatenate the whole string to a well-formed longitude and return $coordinate = $integerPart . '.' . $decimalPart; // test if value is in the possible range. longitude can be -180 to +180. // latitude can be -90 to +90 // At this point, our minus, if there, is stored to 'negative' // therefore we just test if integerpart is bigger than 90 if ($coordinate > $upperRange) { $coordinate = $upperRange; } // reapply signed/unsigned and return return $negative . $coordinate; } }