I can query and get nearest locations to the client with degrees:
serviceQuery = serviceQuery.Where(s => s.Location.Distance(currentLocation) < <degree>)
.OrderBy(s => s.Location.Distance(currentLocation));
Location is NetTopologySuite.Geometries.Point
type in C# and geography
in SQL Server.
How can I provide meter instead of degree in query and also get meter distance instead of degree? Converting the result degree to meter on client-side is acceptable.
I found out the problem.
PostgreSQL (that we are using now) and probably other databases have two types for spatial data: Geometry and Geography.
You can refer to these links for more information (Link 1, Link 2).
Long story short, if you are working with earth's lat/long and you want your calculations to use meter unit, you need to use the Geography type.
Attribute:
[Column(TypeName="geography (point)")]
public Point Location { get; set; }
Fluent API:
builder.Entity<YourEntity>()
.Property(e => e.Location)
.HasColumnType("geography (point)");
If you don't specify, the default would be Geometry which is for Cartesian coordinates.
And by the way, the SRID of the database data must be the same as the location you use for query.