@@ -12,21 +12,22 @@ import { isLoading } from "@/lib/context";
1212const parseCoordinatesFromText = (
1313 text : string ,
1414) : { lat : number | null ; lng : number | null } => {
15- // Format: decimal degrees (e.g., 37.7749, -122.4194)
16- const decimalPattern = / ( - ? \d + \. \d + ) \s * , \s * ( - ? \d + \. \d + ) / ;
15+ // Format: decimal degrees (e.g., 37.7749, -122.4194 or 37,7749, -122,4194 )
16+ const decimalPattern = / ( - ? \d + [ . , ] \d + ) \s * , \s * ( - ? \d + [ . , ] \d + ) / ;
1717
1818 // Format: degrees, minutes, seconds (e.g., 37°46'26"N, 122°25'10"W)
1919 const dmsPattern =
2020 / ( \d + ) ° \s * ( \d + ) [ ' ′ ] ? \s * (?: ( \d + (?: \. \d + ) ? ) [ " ″ ] ? \s * ) ? ( [ N S ] ) [ , \s ] + ( \d + ) ° \s * ( \d + ) [ ' ′ ] ? \s * (?: ( \d + (?: \. \d + ) ? ) [ " ″ ] ? \s * ) ? ( [ E W ] ) / i;
2121
22- // Format: decimal degrees with comma as separator and cardinal direction (e.g., 48,89607° N, 9,09885° E)
23- const euroDecimalPattern = / ( \d + , \d + ) ° \s * ( [ N S ] ) \s * , \s * ( \d + , \d + ) ° \s * ( [ E W ] ) / i;
22+ // Format: decimal degrees with cardinal directions (e.g., 48,89607° N, 9,09885° E or 48.89607° N, 9.09885° E)
23+ const decimalCardinalPattern =
24+ / ( \d + [ . , ] \d + ) ° \s * ( [ N S ] ) \s * , \s * ( \d + [ . , ] \d + ) ° \s * ( [ E W ] ) / i;
2425
2526 const decimalMatch = text . match ( decimalPattern ) ;
2627 if ( decimalMatch ) {
2728 return {
28- lat : parseFloat ( decimalMatch [ 1 ] ) ,
29- lng : parseFloat ( decimalMatch [ 2 ] ) ,
29+ lat : parseFloat ( decimalMatch [ 1 ] . replace ( "," , "." ) ) ,
30+ lng : parseFloat ( decimalMatch [ 2 ] . replace ( "," , "." ) ) ,
3031 } ;
3132 }
3233
@@ -47,13 +48,13 @@ const parseCoordinatesFromText = (
4748 return { lat, lng } ;
4849 }
4950
50- const euroDecimalMatch = text . match ( euroDecimalPattern ) ;
51- if ( euroDecimalMatch ) {
52- let lat = parseFloat ( euroDecimalMatch [ 1 ] . replace ( "," , "." ) ) ;
53- let lng = parseFloat ( euroDecimalMatch [ 3 ] . replace ( "," , "." ) ) ;
51+ const decimalCardinalMatch = text . match ( decimalCardinalPattern ) ;
52+ if ( decimalCardinalMatch ) {
53+ let lat = parseFloat ( decimalCardinalMatch [ 1 ] . replace ( "," , "." ) ) ;
54+ let lng = parseFloat ( decimalCardinalMatch [ 3 ] . replace ( "," , "." ) ) ;
5455
55- if ( euroDecimalMatch [ 2 ] . toUpperCase ( ) === "S" ) lat = - lat ;
56- if ( euroDecimalMatch [ 4 ] . toUpperCase ( ) === "W" ) lng = - lng ;
56+ if ( decimalCardinalMatch [ 2 ] . toUpperCase ( ) === "S" ) lat = - lat ;
57+ if ( decimalCardinalMatch [ 4 ] . toUpperCase ( ) === "W" ) lng = - lng ;
5758
5859 return { lat, lng } ;
5960 }
0 commit comments