Advertisement
Guest User

Untitled

a guest
Oct 30th, 2014
136
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.95 KB | None | 0 0
  1. public object DistanceFrom(
  2. IEnumerable<Coordinate> coordinates) {
  3. IEnumerable<DbGeography> addresses = coordinates.Select(
  4. c =>
  5. DbGeography.FromText(String.Format("POINT ({0} {1})", c.Longitude, c.Latitude)));
  6. IEnumerable<VehicleGeography> vehicles = this.GPSInsightProvider.Query().Document.Placemarks.Select(
  7. p =>
  8. new VehicleGeography {
  9. DriverName = p.DriverName,
  10. Point = DbGeography.FromText(String.Format("POINT ({0} {1})", p.Point.Longitude, p.Point.Latitude))
  11. });
  12. ICollection<object> technicians = new List<object>();
  13.  
  14. foreach (DbGeography address in addresses) {
  15. technicians.Add(vehicles.Select(
  16. v =>
  17. new {
  18. DriverName = v.DriverName,
  19. Distance = v.Point.Distance(address) / 1609.344
  20. }).Where(
  21. v =>
  22. v.Distance.HasValue).OrderBy(
  23. v =>
  24. v.Distance).Take(3).Select(
  25. v =>
  26. new {
  27. DriverName = v.DriverName,
  28. Distance = String.Format("{0:#.#}", v.Distance)
  29. }));
  30. }
  31.  
  32. return technicians;
  33. }
  34.  
  35. public object DistanceFrom(IEnumerable<Coordinate> coordinates)
  36. {
  37. IEnumerable<DbGeography> addresses = coordinates.Select(c =>
  38. DbGeography.FromText(String.Format("POINT ({0} {1})", c.Longitude, c.Latitude)));
  39. IEnumerable<VehicleGeography> vehicles = this.GPSInsightProvider.Query().Document.Placemarks.Select(p =>
  40. new VehicleGeography
  41. {
  42. DriverName = p.DriverName,
  43. Point = DbGeography.FromText(String.Format("POINT ({0} {1})", p.Point.Longitude, p.Point.Latitude))
  44. });
  45. ICollection<object> technicians = new List<object>();
  46.  
  47. foreach (DbGeography address in addresses)
  48. {
  49. technicians.Add(
  50. vehicles
  51. .Select(v =>
  52. new
  53. {
  54. DriverName = v.DriverName,
  55. Distance = v.Point.Distance(address) / 1609.344
  56. })
  57. .Where(v =>v.Distance.HasValue)
  58. .OrderBy(v =>v.Distance)
  59. .Take(3)
  60. .Select(v =>
  61. new
  62. {
  63. DriverName = v.DriverName,
  64. Distance = String.Format("{0:#.#}", v.Distance)
  65. }));
  66. }
  67.  
  68. return technicians;
  69. }
  70.  
  71. technicians.Add(
  72. vehicles
  73. .Select(v =>
  74. new
  75. {
  76. DriverName = v.DriverName,
  77. Distance = v.Point.Distance(address) / 1609.344
  78. })
  79. .Where(v =>v.Distance.HasValue)
  80. .OrderBy(v =>v.Distance)
  81. .Take(3)
  82. .Select(v =>
  83. new
  84. {
  85. DriverName = v.DriverName,
  86. Distance = String.Format("{0:#.#}", v.Distance)
  87. }));
  88.  
  89. var vehiclesByDistance =
  90. vehicles
  91. .Select(v =>
  92. new
  93. {
  94. DriverName = v.DriverName,
  95. Distance = v.Point.Distance(address) / 1609.344
  96. })
  97. .Where(v =>v.Distance.HasValue)
  98. .OrderBy(v =>v.Distance);
  99.  
  100. technicians.Add(
  101. vehiclesByDistance
  102. .Take(3)
  103. .Select(v =>
  104. new
  105. {
  106. DriverName = v.DriverName,
  107. Distance = String.Format("{0:#.#}", v.Distance)
  108. }));
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement