I'm building an application that I need to be able to search for businesses, based on their 'delivery area'
For example, London Business
provides services up to 10000 meters from a lat/lon
Southampton Business
provides services 1000 meters from a lat/lon
I'm part of the way there, using EF Core and NetTopologySuite.
I'm using the following simplified code:
var geometryFactory = NtsGeometryServices.Instance.CreateGeometryFactory(srid: 4326);
var londonBusiness = new Business
{
Name = "London Business",
Area = geometryFactory.CreatePoint(new Coordinate(-0.127758, 51.507351)),
AreaRadius = 10000
};
var southamptonBusiness = new Business
{
Name = "Southampton Business",
Area = geometryFactory.CreatePoint(new Coordinate(1.4044, 50.9097)),
AreaRadius = 1000
};
await _dbContext.Businesses.AddAsync(londonBusiness);
await _dbContext.Businesses.AddAsync(southamptonBusiness);
await _dbContext.SaveChangesAsync();
// QUERY
// this is very clsoe to the londonBusiness (a couple of km)
var searchLocation = _geometryFactory.CreatePoint(new Coordinate(-0.142500, 51.539188));
var query = _dbContext
.Businesses
.Where(x => x.AreaLocation.Distance(searchLocation) <= x.AreaRadius)
.ToList()
// this projection is for debug purposes
.Select(x => new
{
Distance = x.AreaLocation.Distance(searchLocation),
radius = x.AreaRadius
});
This is returning the following results:
{ Name = "London Business", Distance = 0.035084485645370242, Radius = 10000 }
{ Name = "Southampton Business", Distance = 1.6700762713552944, Radius = 1000 }
So, I think my issue lies somewhere with the distance(s) I'm clearly misunderstanding what the distances are / relate to. They're relatively correct - the London Business distance is much much smaller than the Southampton Business
Is there a way to query by meters?