Created
July 29, 2015 10:09
-
-
Save bodia-uz/4d400ad15aebbcd049d0 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| var pabs = new [] | |
| { | |
| new { | |
| id = 0, name = "Green Way", | |
| address= "Льва Толстого вул., 31", | |
| lat = 48.62079866700977, | |
| lng = 22.291045737400175 | |
| }, | |
| new { | |
| id = 1, name = "R4", | |
| address= "Свободи просп., 3", | |
| lat = 48.61990841762924, | |
| lng = 22.288635653378783 | |
| }, | |
| new { | |
| id = 3, name = "Акваріум", | |
| address= "Льва Толстого вул., 44", | |
| lat = 48.6215821602211, | |
| lng = 22.289350484427537 | |
| } | |
| , | |
| new { | |
| id = 4, name = "готель Ужгород", | |
| address= "", | |
| lat = 48.62115128530497, | |
| lng = 22.28676487962975 | |
| } | |
| , | |
| new { | |
| id = 5, name = "Спортбар", | |
| address= "Капушанська вул., 26", | |
| lat = 48.61873629642148, | |
| lng = 22.289441813611752 | |
| } | |
| }.AsQueryable().Dump("Pabs"); | |
| var p1 = new {lat = 48.615672658147666, lng = 22.290330284830027}; | |
| var d = 0.5; | |
| var selectedPubs = | |
| from p2 in pabs | |
| let R = 6371// Radius of the Earth in km | |
| let dLat = (p2.lat - p1.lat) * Math.PI / 180 | |
| let dLon = (p2.lng - p1.lng) * Math.PI / 180 | |
| let a = Math.Sin(dLat / 2) * Math.Sin(dLat / 2) + Math.Cos(p1.lat * Math.PI / 180) * Math.Cos(p2.lat * Math.PI / 180) * Math.Sin(dLon / 2) * Math.Sin(dLon / 2) | |
| let c = 2 * Math.Atan2(Math.Sqrt(a), Math.Sqrt(1 - a)) | |
| let distance = R * c | |
| where distance<=d | |
| select new {p2.id, p2.name, p2.address, p2.lat,p2.lng, distance = distance>1?distance.ToString("0.0") + " км":(distance*1000).ToString("0")+" м"}; | |
| selectedPubs.OrderBy(x=>x.distance).Dump(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment