在 Xamarin 窗体中使用当前坐标筛选 SQLite 表

Filter SQLite table with current coordinates in Xamarin forms

提问人:Sid 提问时间:10/26/2023 更新时间:10/26/2023 访问量:72

问:

我有 Xmarin 表单跨平台应用程序,其中有一个名为 Customers 的表存储在 SQLite 数据库中。此表包含每个客户的 Lattitude 和 Longitude。我可以得到最新的GPS。我想要的是用当前的 GPS 过滤最近的客户。

    public class Customer
    {
        [PrimaryKey, AutoIncrement]
        public long Id { get; set; }        
        public string Number { get; set; }
        public string Name { get; set; }
        public string Address { get; set; }
        public string MobileNo { get; set; }
        public string Email { get; set; }
        public int CreditDays { get; set; }
        public decimal? Latitude { get; set; }
        public decimal? Longitude { get; set; }
        public string Note { get; set; }
    }

public Contact GetContactById(long id)
  {
     return _db.Table<Contact>().Where(c => c.Id == id).FirstOrDefault();
  }

我想使用当前的纬度和经度筛选 Customer 表,以查找 100 米内最近的客户。

有人可以使用任何示例代码来过滤带有实体框架的SQLite吗?

C# SQLite Xamarin Xamarin.Forms 地理位置

评论

0赞 Jason 10/26/2023
您可以轻松地在用户位置周围创建一个边界框,并使用它来过滤。这稍微不那么准确,但比进行半径搜索要简单得多
0赞 Sid 10/28/2023
@Jason我以前没有这样做过。你有代码示例吗?
0赞 Jason 10/28/2023
stackoverflow.com/questions/18295825/......
0赞 Sid 10/28/2023
我想要的是一种过滤SQLite数据的方法。我有一个客户表,每个客户都有纬度和液化天然气。该表中可能有超过 10000 条记录。我想找到离我当前位置最近的客户。
0赞 Jason 10/28/2023
我明白你想要什么。我不明白你被困在哪里了。我提供的链接你不明白吗?

答: 暂无答案