private async void Init() { try { var start = new Position(); start.Latitude = driver.Lat; start.Longitude = driver.Lon; this.destination = await Ride2GoService.GetPosition(this.destinationName); var routeResult = await Ride2GoService.GetRoute(start, destination, this.riderPosition); var points = routeResult.Locations; this.MapView.AddOverlay(MKPolyline.FromCoordinates(points)); var annotation = new BasicMapAnnotation(new CLLocationCoordinate2D(driver.Lat, driver.Lon), driver.Name); this.MapView.AddAnnotation(annotation); this.TimeLabel.Text = routeResult.Eta; this.timer = new Timer(); timer.Interval = 2500; timer.Start(); timer.Elapsed += this.TimerTick; } catch (Exception e) { Application.PresentOKAlert("hallo", e.Message, this, () => { }); } }
private async void TimerHasTicked() { this.driver = await Ride2GoService.GetDriverUpdate(pollCount); var driverPosition = new Position() { Latitude = driver.Lat, Longitude = driver.Lon }; var routeResult = await Ride2GoService.GetRoute(driverPosition, this.riderPosition, null); this.InvokeOnMainThread( () => { var annotation = new BasicMapAnnotation(new CLLocationCoordinate2D(driver.Lat, driver.Lon), driver.Name); this.MapView.RemoveAnnotations(this.MapView.Annotations); this.MapView.AddAnnotation(annotation); this.TimeLabel.Text = routeResult.Eta; pollCount++; }); if (pollCount > 2) { this.timer.Elapsed -= TimerTick; Application.PresentOKAlert("Driver arrived", "Look for the blinking car", this, () => { }); this.InvokeOnMainThread(() => { this.TimeLabel.Text = "arrived"; }); Ride2GoService.MakeTheCarBlink(); } }
private async void OverlayNewRoute(Rider rider) { this.MapView.RemoveOverlay(this.firstRoute); //rider.Position var pickupPoint = new Position(); pickupPoint.Latitude = rider.Lat; pickupPoint.Longitude = rider.Lon; var routeResult = await Ride2GoService.GetRoute(this.driverPosition, this.destinationPosition, pickupPoint); this.MapView.AddOverlay(MKPolyline.FromCoordinates(routeResult.Locations)); var annotation = new BasicMapAnnotation(new CLLocationCoordinate2D(rider.Lat, rider.Lon), rider.Name); this.MapView.AddAnnotation(annotation); }