C# - LINQ - shortest distance by GPS latitude and longitude

前端 未结 3 1625
甜味超标
甜味超标 2021-02-14 16:38

I have database and in it I have class hotel with gps coordinates. I want to get closest places to coordinates which I choose.

I think It should look like this (I found

3条回答
  •  没有蜡笔的小新
    2021-02-14 17:28

    You can use the object initializer instead of parameterized constructor:

    var nearest = (from h in db.hotels
               let geo = new GeoCoordinate{ Latitude = h.gps.lat, Longitude = h.gps.lng}
               orderby geo.GetDistanceTo(coord)
               select h).Take(10);
    

    But you will likely have problems caused by the GetDistanceTo method, could you provide the implementation of that method?

提交回复
热议问题