Find all nearby customers within a given distance using longitude and latitude

大兔子大兔子 提交于 2019-12-04 14:41:38
Fung

A little modification of my answer to a similar 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);

You need to add reference to System.Device.dll.

Using haversine formula

User will have current location, customer location and distance So using haversine formula calculate distance (d1) using current location and customer location Then compare calculated distance (d1) with required distance.

Logic is calculated distance <= required distance then it means current customer is in required distance else customer is outside the radial distance

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!