@@ -1225,6 +1225,49 @@ describe('collections-rest', () => {
12251225 expect ( result . docs ) . toHaveLength ( 0 )
12261226 } )
12271227
1228+ // https://github.com/payloadcms/payload/issues/14471 - ensure geospatial queries use true geodetic meters, not the distorted meters of EPSG:3857
1229+ it ( 'should use true geodetic meters at high latitudes' , async ( ) => {
1230+ if ( payload . db . name === 'sqlite' ) {
1231+ return
1232+ }
1233+
1234+ // A point ~10 km north of NYC: lat += 10000/111320 ≈ 0.0898°
1235+ const queryLng = - 74.0059
1236+ const queryLat = 40.7128
1237+ const pointLat = queryLat + 0.0898 // ~10 km north
1238+ let createdId : number | string | undefined
1239+
1240+ try {
1241+ const created = await payload . create ( {
1242+ collection : pointSlug ,
1243+ data : { point : [ queryLng , pointLat ] } ,
1244+ } )
1245+
1246+ createdId = created . id
1247+
1248+ // Query with 12 km radius — the point at ~10 km should be within range.
1249+ // With the old EPSG:3857 approach, the effective radius at this latitude was
1250+ // only ~9 km, causing the point to be missed.
1251+ const response = await restClient . GET ( `/${ pointSlug } ` , {
1252+ query : {
1253+ where : {
1254+ point : {
1255+ near : `${ queryLng } , ${ queryLat } , 12000` ,
1256+ } ,
1257+ } ,
1258+ } ,
1259+ } )
1260+ const result : any = await response . json ( )
1261+
1262+ expect ( response . status ) . toEqual ( 200 )
1263+ expect ( result . docs . map ( ( d : { id : number | string } ) => d . id ) ) . toContain ( createdId )
1264+ } finally {
1265+ if ( createdId !== undefined ) {
1266+ await payload . delete ( { collection : pointSlug , id : createdId } )
1267+ }
1268+ }
1269+ } )
1270+
12281271 it ( 'should not return a point far away' , async ( ) => {
12291272 if ( payload . db . name === 'sqlite' ) {
12301273 return
0 commit comments