private async void GetMyValidBookedReservations() { ShowLoadingView("Loading data..."); _pickups = new List <Dictionary <string, string> > (); try { var lResult = LocationHelper.GetLocationResult(); if (_selectedMarker != null) { _selectedMarker.Map = null; mapView.Clear(); } if (_currentMarkers != null) { foreach (var marker in _currentMarkers) { marker.Map = null; } _currentMarkers.Clear(); mapView.MarkerInfoWindow = null; } NSDateFormatter dateFormat = new NSDateFormatter(); dateFormat.DateFormat = "MM/dd/yyyy"; NSDate now = NSDate.FromTimeIntervalSinceReferenceDate((DateTime.Now - (new DateTime(2001, 1, 1, 0, 0, 0))).TotalSeconds); var strNow = dateFormat.ToString(now); var customerID = AppSettings.UserID; // please take a look it, Pavel var dic = new Dictionary <String, String> { { Constant.GETREADYFORPICKUPLIST_CUSTOMERID, "553890" }, { Constant.GETREADYFORPICKUPLIST_CURRENTDATE, "2/13/2015" } }; //var dic = new Dictionary<String, String> //{ // {Constant.GETREADYFORPICKUPLIST_CUSTOMERID, customerID}, // {Constant.GETREADYFORPICKUPLIST_CURRENTDATE, strNow} //}; var result = await AppData.ApiCall(Constant.GETREADYFORPICKUPLIST, dic); var tt = (GetReadyForPickupListResponse)AppData.ParseResponse(Constant.GETREADYFORPICKUPLIST, result); var availableReservations = tt.PickupList; for (int i = 0; i < availableReservations.Count; i++) { var reservation = availableReservations[i]; Task runSync = Task.Factory.StartNew(async() => { var pickupData = await GetPickupDataForReservation(reservation); _pickups.Add(pickupData); }).Unwrap(); runSync.Wait(); } var bounds = new CoordinateBounds(); var listReservations = new List <KeyValuePair <object, string> >(); listReservations.Add(new KeyValuePair <object, string>("0", "Ready for all rides")); foreach (Dictionary <String, String> pickup in _pickups) { var marker = new Marker { Position = new CLLocationCoordinate2D(double.Parse(pickup["Latitude"]), double.Parse(pickup["Longitude"])), Map = mapView, Icon = rotateImage(UIImage.FromBundle(getMapVehicleIconByServiceID(pickup["ServiceID"])), float.Parse(pickup["Angle"])), ZIndex = int.Parse(pickup["ResID"]) }; _currentMarkers.Add(marker); bounds = bounds.Including(marker.Position); listReservations.Add(new KeyValuePair <object, string>(pickup["ResID"], pickup["DisplayTxt"])); //string.Format("Shared Van (7 Passengers) \n 3:45 Pick-Up to Los Angeles", pickup["ResID"], pickup["ResType"]))); } if (_pickups.Count > 0) { btnReadyPickup.BackgroundColor = UIColor.Green; btnReadyPickup.SetTitle(string.Format("READY FOR PICKUP ({0})", _pickups.Count.ToString()), UIControlState.Normal); SetupReadyPickup(txtBtnReadyPickup, listReservations, CallForReadyPickup); } else { btnReadyPickup.BackgroundColor = UIColor.Gray; btnReadyPickup.SetTitle("READY FOR PICKUP", UIControlState.Normal); } bounds = bounds.Including(new CLLocationCoordinate2D(lResult.Latitude, lResult.Longitude)); _selectedMarker = new Marker { Position = new CLLocationCoordinate2D(lResult.Latitude, lResult.Longitude), Map = mapView, Icon = UIImage.FromBundle("icon_mylocation.png") }; mapView.SelectedMarker = _selectedMarker; if (_pickups.Count > 0) { mapView.Animate(CameraUpdate.FitBounds(bounds, 100f)); } mapView.TappedMarker = (map, maker) => { mapView.MarkerInfoWindow = new GMSInfoFor(markerInfoWindow); return(false); }; } catch (Exception ex) { CrashReporter.Report(ex); HideLoadingView(); return; } HideLoadingView(); }
UIView markerInfoWindow(UIView view, Marker marker) { if (marker.ZIndex == 0) { return(null); } MapMarkerView v = MapMarkerView.Create(); var resID = marker.ZIndex.ToString(); for (int i = 0; i < _pickups.Count; i++) { if (_pickups [i]["ResID"] == resID) { var pickup = _pickups [i]; var pos1 = new CLLocation(double.Parse(pickup ["Latitude"]), double.Parse(pickup ["Longitude"])); var pos2 = new CLLocation(LocationHelper.GetLocationResult().Latitude, LocationHelper.GetLocationResult().Longitude); var distance = string.Format("{0}m", (Math.Round(pos1.DistanceFrom(pos2))).ToString()); DateTime pDate = DateTime.Parse(pickup ["Date"]); string[] arrDate = pDate.GetDateTimeFormats(); string strType = pickup ["ArvDep"] == "1" ? "Drop-Off" : "Pick-Up"; string title = string.Format("{0} - {1} {2}", pickup ["ResType"], arrDate[108], strType); v.SetView(title, distance); } } return(v); }