我正在构建一个应用程序,我需要能够根据他们的“交付区域”搜索企业
例如,London Business
提供距离纬度/经度高达 10000 米的
Southampton Business
服务 提供距离纬度/经度 1000 米的服务
我是其中的一部分,使用 EF Core 和 NetTopologySuite。
我正在使用以下简化代码:
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
});
这将返回以下结果:
{ Name = "London Business", Distance = 0.035084485645370242, Radius = 10000 }
{ Name = "Southampton Business", Distance = 1.6700762713552944, Radius = 1000 }
所以,我认为我的问题在于距离的某个地方,我显然误解了距离是/相关的。他们是相对正确的 - 伦敦商业距离远小于南安普敦商业
有没有按米查询的方法?