C# C-linq坐标测量问题

C# C-linq坐标测量问题,c#,gps,geocoding,distance,C#,Gps,Geocoding,Distance,我目前正在开发服务器端到应用程序, 在应用程序中,我有很多兴趣点在大面积超过1000点 我想找到离用户设备最近的点。 我尝试使用: .GetDistanceTo(GeoCoordinate); 图书馆: System.Device.Location; 查询示例: from point in db.Points where ((new GeoCoordinate(point.lat,point.lng)).GetDistanceTo(new GeoCoordinate(coordin

我目前正在开发服务器端到应用程序, 在应用程序中,我有很多兴趣点在大面积超过1000点 我想找到离用户设备最近的点。 我尝试使用:

.GetDistanceTo(GeoCoordinate);
图书馆:

 System.Device.Location;
查询示例:

  from point in db.Points
  where ((new GeoCoordinate(point.lat,point.lng)).GetDistanceTo(new GeoCoordinate(coordinates[0],coordinates[1]))<1000)) 
  select point
但在Linq查询中,它不受支持,如果我尝试在列表或数组中使用它,则会花费太长时间

我怎样才能做得更好更快?
谢谢

我假设您经常执行此计算,否则迭代1000个点不会花费大量时间-当然不到一秒钟

考虑将内存中的点缓存为地理坐标,因为我猜大部分时间可能用于分配内存和实例化对象,而不是计算距离。从现有的地理坐标列表中,您可以对已经实例化的现有地理坐标进行计算

例: 在应用程序加载时,将所有点存储到内存中,可能存储在后台线程上

List<GeoCoordinate> points = from point in db.Points select new GeoCoordinate(point.lat, point.lng);
然后,抓住你要搜索的点,在点上循环

var gcSearch = new GeoCoordinate(coordinates[0], coordinates[1]);
var searchDistance = 1000;
var results = from pSearch in points 
              where pSearch.GetDistanceTo(gcSearch) < searchDistance
              select pSearch;

如果仍然不够快,考虑缓存最后一个搜索点,如果新的搜索在同一个范围内,则重新生成已知的列表。

// in class definition
static GeoCoordinate lastSearchedPoint = null;
static List<GeoCoordinate> lastSearchedResults = null
const searchFudgeDistance = 100;

//in search method
var gcSearch = new GeoCoordinate(coordinates[0], coordinates[1]);
if (lastSearchedPoint != null && gcSearch.GetDistanceTo(lastSearchedPoint) < searchFudgeDistance)
    return lastSearchedResults;
lastSearchedPoint = gcSearch;

var searchDistance = 1000;
var results = from pSearch in points 
              where pSearch.GetDistanceTo(gcSearch) < searchDistance
              select pSearch;
//store the results for future searches
lastSearchedResults = results;

你能添加更多的代码和上下文吗?什么LINQ查询?这个GetDistanceTo方法是在哪里定义的?你提供的信息越多,得到答案的机会就越大。我已经添加了mpre信息。。希望它能帮助您真正了解空间分区和位置敏感哈希。遗憾的是,我手头没有资料,但使用术语K-最近邻搜索应该可以让您开始搜索。