声明变量

//假设当前坐标
double lon1 = 113.336028;
double lat1 = 23.21745;
//距离m
double distance = 1000 * 5;
private static  double EARTH_RADIUS = 6378137;//赤道半径(单位m)


主要方法[LantitudeLongitudeDist]

public static double LantitudeLongitudeDist(double lon1, double lat1, double lon2, double lat2)
{

double d = Math.Sqrt((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2) + (z1 - z2) * (z1 - z2));
//余弦定理求夹角
double dist = theta * EARTH_RADIUS;
return dist;
}


遍历判断,得到符合条件的门店

 //准备存储符合条件门店的泛型类
List<ShopPlaceInfo> placelist = new List<ShopPlaceInfo>();
//查询数据库的门店地址坐标
DataTable PlaceDt = kis_web.DBHelper.GetTable("select shopName, shopadress, Lat as lat,Lng as lon from Shop where Lat is not null and   Lng is not null");
foreach (DataRow item in PlaceDt.Rows)
{
double currLon = Convert.ToDouble(item["lon"]);
double currLat = Convert.ToDouble(item["lat"]);
double place = LantitudeLongitudeDist(lon1, lat1, currLon, currLat);
//如果当前距离和该门店距离相差小于指定N公里
if (place <= distance)
{
//放进符合条件门店的泛型类中
{
lat = currLat,
lon = currLon,
saleQty = 1,
saleAmount = 100,
distance = place,
shopName = item["shopName"].ToString()

});
}
}
//这样最终得到了符合条件的门店Json数据
string reJson = JsonConvert.SerializeObject(placelist);


2019/9/18后续补充

   private static double rad(double d)
{
return d * Math.PI / 180.0;
}

posted @ 2019-04-24 16:33  君宁天下  阅读(231)  评论(0编辑  收藏