public void OnDataChange(DataSnapshot snapshot) { if (snapshot.Value != null) { var child = snapshot.Children.ToEnumerable <DataSnapshot>(); availableDrivers.Clear(); foreach (DataSnapshot data in child) { if (data.Child("ride_id").Value != null) { if (data.Child("ride_id").Value.ToString() == "waiting") { //Get Driver Location double latitude = double.Parse(data.Child("location").Child("latitude").Value.ToString()); double longitude = double.Parse(data.Child("location").Child("longitude").Value.ToString()); LatLng driverLocation = new LatLng(latitude, longitude); AvailableDriver driver = new AvailableDriver(); //compute Distance between Pickup Location and Driver Location driver.DistanceFromPickup = SphericalUtil.ComputeDistanceBetween(mPickupLoction, driverLocation); driver.ID = data.Key; availableDrivers.Add(driver); } } } if (availableDrivers.Count > 0) { availableDrivers = availableDrivers.OrderBy(o => o.DistanceFromPickup).ToList(); DriversFound?.Invoke(this, new DriverFoundEventArgs { Drivers = availableDrivers }); } else { DriverNotFound.Invoke(this, new EventArgs()); } } else { DriverNotFound.Invoke(this, new EventArgs()); } }
public void Create(List <ActiveDrivers> activeDrivers) { availableDrivers = activeDrivers; if (availableDrivers.Count > 0) { availableDrivers.ForEach(x => { LatLng driverLocation = new LatLng(Convert.ToDouble(x.Latitude), Convert.ToDouble(x.Longitude)); LatLng pickUpLocation = new LatLng(Convert.ToDouble(rides.RidesInfo.LocationInfo.PickupLatitude), Convert.ToDouble(rides.RidesInfo.LocationInfo.PickupLongitude)); x.DistanceFromPickup = SphericalUtil.ComputeDistanceBetween(pickUpLocation, driverLocation); }); availableDrivers = availableDrivers.OrderBy(o => o.DistanceFromPickup).ToList(); DriversFound?.Invoke(this, new DriverFoundEventArgs { Drivers = availableDrivers, Ride = rides }); } else { DriverNotFound.Invoke(this, new EventArgs()); } }
private void showDistance() { double distance = SphericalUtil.ComputeDistanceBetween(mMarkerA.Position, mMarkerB.Position); mTextView.Text = "The markers are " + formatNumber(distance) + " apart."; }