gpt4 book ai didi

c# - 使用经度和纬度查找给定距离内的所有附近客户

转载 作者:行者123 更新时间:2023-11-30 13:38:00 24 4
gpt4 key购买 nike

我有一个包含客户经度和纬度的数据库,我有一个搜索表单,用户将在其中输入日志/纬度,距离下拉列表包含 50 英里、100 英里,....当用户单击搜索时,我想写一个linq 查询从数据库中获取在此距离半径内的所有客户。如何使用 C# 和 linq 实现这一点?

更新:
我找到了这个 https://stackoverflow.com/a/1654365/20126但这给出的是正方形而不是半径

最佳答案

我对类似 question 的回答稍作修改:

// radius is the distance in meters
var center = new GeoCoordinate(latitude, longitude);
var result = customers.Select(x => new GeoCoordinate(x.Latitude, x.Longitude))
.Where(x => x.GetDistanceTo(center) < radius);

您需要添加对 System.Device.dll 的引用。

关于c# - 使用经度和纬度查找给定距离内的所有附近客户,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19478874/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com