private async void SearchDestinationBox_SuggestionChosen(AutoSuggestBox sender, AutoSuggestBoxSuggestionChosenEventArgs args) { if (!IsInternet()) { await new MessageDialog("Seems you are not connected to the Internet").ShowAsync(); return; } else { _destination = args.SelectedItem.ToString(); CabsAPI api = new CabsAPI(); GeoResponse location; var localSettings = Windows.Storage.ApplicationData.Current.LocalSettings; token = localSettings.Values["Token"].ToString(); location = await api.GeoCodingResult(token, args.SelectedItem.ToString()); if (location.Code == ResponseCode.SUCCESS) { dlat = location.Position.Latitude; dlng = location.Position.Longitude; AddMapIcon(double.Parse(dlat), double.Parse(dlng)); _cabsView.SetLatLng(dlat, dlng); ShowLoader(true); await _cabsView.RefreshView(CabsListViewModel.REFRESH_ESTIMATE); CabsListView.ItemsSource = _cabsView.Cabs; ShowLoader(false); } else { await new MessageDialog("Error retrieving Geoposition").ShowAsync(); return; } } }
private async void SearchSourceBox_SuggestionChosen(AutoSuggestBox sender, AutoSuggestBoxSuggestionChosenEventArgs args) { if (!IsInternet()) { await new MessageDialog("Seems you are not connected to the Internet").ShowAsync(); return; } else { _source = args.SelectedItem.ToString(); flag = 1; progress.IsActive = true; //string dlat, dlng, token; var localSettings = Windows.Storage.ApplicationData.Current.LocalSettings; token = localSettings.Values["Token"].ToString(); GeoResponse location; CabsAPI api = new CabsAPI(); location = await api.GeoCodingResult(token, args.SelectedItem.ToString()); if (location.Code == ResponseCode.SUCCESS) { slat = location.Position.Latitude; slng = location.Position.Longitude; BasicGeoposition curPos = new BasicGeoposition(); curPos.Latitude = double.Parse(slat); curPos.Longitude = double.Parse(slng); await MyMap.TrySetViewAsync(new Geopoint(curPos), 17D); AddMapIcon(double.Parse(slat), double.Parse(slng)); CabsResponse response = await api.GetNearbyCabs(slat, slng, Token); if (response.Code == ResponseCode.SUCCESS) { progress.IsActive = false; CabsListView.ItemsSource = response.Cabs; } else { await new MessageDialog("Error fetching nearby cabs").ShowAsync(); return; } } else { await new MessageDialog("Error retrieving Geoposition coordinates").ShowAsync(); return; } } }
private async void mDestinationTextBoxClicked(object sender, AdapterView.ItemClickEventArgs e) { dest = destinationSuggestionsAdapter.GetObjectAt(e.Position); System.Diagnostics.Debug.Write(dest); autoDestinationBox.Text = destinationSuggestionsAdapter.GetObjectAt(e.Position); if (msourceRecieved != null && dest != null) { GeoResponse mResponseGetDestlatlng = await api.GeoCodingResult(token, dest); dlat = mResponseGetDestlatlng.Position.Latitude; dlng = mResponseGetDestlatlng.Position.Longitude; setDestinationMarker(dest); mLoadingDialog.Show(); PriceEstimateResponse mRes = await api.GetEstimate(token, slat, slng, dlat, dlng); mCabsEst = mRes.Estimates; CabRecyclerAdapterWithDestination mAdapter = new CabRecyclerAdapterWithDestination(Application.Context, mCabsEst, mActivity); mAdapter.ItemClick1 += Item_Click_New; mRecyclerView.SetAdapter(mAdapter); mLoadingDialog.Dismiss(); } }
private async Task SendCompletionMessageForCostEstimate(string source, string destination) { string slat, slng, dlat, dlng, token, mDisplay; slat = slng = dlng = dlat = null; var mUserMessage = new VoiceCommandUserMessage(); var mUserPrompt = new VoiceCommandUserMessage(); VoiceCommandResponse mResponseError; VoiceCommandContentTile mCabTile = new VoiceCommandContentTile(); CabsAPI mCabsApi = new CabsAPI(); GeoResponse mGeoResp; List <VoiceCommandContentTile> mCabTiles = new List <VoiceCommandContentTile>(); token = Windows.Storage.ApplicationData.Current.LocalSettings.Values["Token"].ToString(); if (destination.Equals("")) { await ShowProgressScreen("Insufficient Info"); mDisplay = "Sorry no destination provided Please enter a valid destination"; mUserMessage.DisplayMessage = mUserMessage.SpokenMessage = mDisplay; mResponseError = VoiceCommandResponse.CreateResponse(mUserMessage); } else { mGeoResp = await mCabsApi.GeoCodingResult(token, destination); if (mGeoResp.Code == ResponseCode.SUCCESS) { dlat = mGeoResp.Position.Latitude; dlng = mGeoResp.Position.Longitude; } else { mDisplay = "Destination not found"; mUserMessage.DisplayMessage = mUserMessage.SpokenMessage = mDisplay; mResponseError = VoiceCommandResponse.CreateResponse(mUserMessage); await voiceServiceConnection.ReportFailureAsync(mResponseError); } } mGeoResp = await mCabsApi.GeoCodingResult(token, source); if (mGeoResp.Code == ResponseCode.SUCCESS) { slat = mGeoResp.Position.Latitude; slng = mGeoResp.Position.Longitude; } else { mDisplay = "Source not found"; mUserMessage.DisplayMessage = mUserMessage.SpokenMessage = mDisplay; mResponseError = VoiceCommandResponse.CreateResponse(mUserMessage); await voiceServiceConnection.ReportFailureAsync(mResponseError); } string EstimatingCabsFromXtoY = "Getting cost Details from " + source + " to " + destination; await ShowProgressScreen(EstimatingCabsFromXtoY); CabsAPI api = new CabsAPI(); string loadingCabsFromXtoY = "Loading Details of cabs from " + source + " to " + destination; await ShowProgressScreen(loadingCabsFromXtoY); GeoResponse sResponse = await api.GeoCodingResult(token, source); GeoResponse dResponse = await api.GeoCodingResult(token, destination); PriceEstimateResponse pResponse = await api.GetEstimate(token, slat, slng, dlat, dlng); var userMessage = new VoiceCommandUserMessage(); var cabTiles = new List <VoiceCommandContentTile>(); List <CabEstimate> cabsAvaialble = pResponse.Estimates; CabEstimate cabSelected; if (cabsAvaialble == null) { string foundNoCabs = "Sorry No Cabs Found"; userMessage.DisplayMessage = foundNoCabs; userMessage.SpokenMessage = foundNoCabs; } else { string message = "Ok! I have found the following Cabs for you"; userMessage.DisplayMessage = message; userMessage.SpokenMessage = message; cabSelected = await AvailableList(cabsAvaialble, "Which cab do you want to book?", "Book the selected cab?"); var userPrompt = new VoiceCommandUserMessage(); VoiceCommandResponse response; string BookCabToDestination = "Booking " + cabSelected.Provider + " with " + cabSelected.Type + " from " + source + " to " + destination + " arriving in " + cabSelected.Eta + " with " + cabSelected.CurrentEstimate.LowRange + " to " + cabSelected.CurrentEstimate.HighRange + " cost estimation"; userPrompt.DisplayMessage = userPrompt.SpokenMessage = BookCabToDestination; var userReprompt = new VoiceCommandUserMessage(); string confirmBookCabToDestination = "Confirm booking"; userReprompt.DisplayMessage = userReprompt.SpokenMessage = confirmBookCabToDestination; response = VoiceCommandResponse.CreateResponseForPrompt(userPrompt, userReprompt, cabTiles); var voiceCommandConfirmation = await voiceServiceConnection.RequestConfirmationAsync(response); if (voiceCommandConfirmation != null) { if (voiceCommandConfirmation.Confirmed == true) { BookingDetailsResponse booking = await api.BookCab(token, sResponse.Position.Latitude, sResponse.Position.Longitude); string BookingCabToDestination = "Booking cab"; await ShowProgressScreen(BookingCabToDestination); var cabShow = new VoiceCommandContentTile(); cabShow.ContentTileType = VoiceCommandContentTileType.TitleWith68x68IconAndText; if (cabSelected.Provider.Equals("UBER")) { cabShow.Image = await StorageFile.GetFileFromApplicationUriAsync(new Uri("ms-appx:///ContosoCabs.VoiceCommandService/img/uber.png")); } else { cabShow.Image = await StorageFile.GetFileFromApplicationUriAsync(new Uri("ms-appx:///ContosoCabs.VoiceCommandService/img/ola.png")); } cabShow.Title = cabSelected.Type; cabShow.TextLine1 = "ETA : " + cabSelected.Eta; cabShow.TextLine2 = "Estimated Fare: " + cabSelected.CurrentEstimate.LowRange + "-" + cabSelected.CurrentEstimate.HighRange; cabShow.TextLine3 = "Call driver at " + booking.BookingData.DriverDetails.Phone_Number; cabTiles.Add(cabShow); var userMessage1 = new VoiceCommandUserMessage(); string BookCabInformation = "Cab booked. your cab driver " + booking.BookingData.DriverDetails.Name + "will be arriving shortly."; //Vehicle number :"+ booking.BookingData.VehicleDetails.License_Plate userMessage.DisplayMessage = userMessage.SpokenMessage = BookCabInformation; userMessage1.DisplayMessage = userMessage1.SpokenMessage = BookCabInformation; response = VoiceCommandResponse.CreateResponse(userMessage1, cabTiles); await voiceServiceConnection.ReportSuccessAsync(response); } else { userMessage = new VoiceCommandUserMessage(); string BookingCabToDestination = "Cancelling cab request..."; await ShowProgressScreen(BookingCabToDestination); string keepingTripToDestination = "Cancelled."; userMessage.DisplayMessage = userMessage.SpokenMessage = keepingTripToDestination; response = VoiceCommandResponse.CreateResponse(userMessage); await voiceServiceConnection.ReportSuccessAsync(response); } } } }
private async Task SendCompletionMessageForBookToCustomLocation(string location) { string slat, dlat, slng, dlng; GeoResponse locationResponse; string gettingCabsToDesiredLocation = "Getting Details of " + location; await ShowProgressScreen(gettingCabsToDesiredLocation); CabsAPI api = new CabsAPI(); string token = Windows.Storage.ApplicationData.Current.LocalSettings.Values["Token"].ToString(); string loadingCabsToDesiredLocation = "Loading Details of cabs to " + location; await ShowProgressScreen(loadingCabsToDesiredLocation); Geolocator locator = new Geolocator(); var userMessage1 = new VoiceCommandUserMessage(); locator.DesiredAccuracyInMeters = 50; var position = await locator.GetGeopositionAsync(); slat = position.Coordinate.Point.Position.Latitude.ToString(); slng = position.Coordinate.Point.Position.Longitude.ToString(); string latlng1 = slat + "," + slng; ReverseGeoResposne reverse = await api.GetReverseCodingResultlatlng(token, latlng1); locationResponse = await api.GeoCodingResult(token, location); dlat = locationResponse.Position.Latitude; dlng = locationResponse.Position.Longitude; PriceEstimateResponse Responseprice = await api.GetEstimate(token, slat, slng, dlat, dlng); List <CabEstimate> desiredList = Responseprice.Estimates; var sortedCabs = desiredList.OrderBy(o => o.CurrentEstimate.HighRange); var userMessage = new VoiceCommandUserMessage(); var cabTiles = new List <VoiceCommandContentTile>(); if (desiredList == null) { string foundNoCabs = "Sorry No Cabs Found"; userMessage.DisplayMessage = foundNoCabs; userMessage.SpokenMessage = foundNoCabs; } else { string message = "Ok! I have found the Best Cab for you"; userMessage.DisplayMessage = message; userMessage.SpokenMessage = message; var cabsNeeded = desiredList[0]; var cabShow = new VoiceCommandContentTile(); cabShow.ContentTileType = VoiceCommandContentTileType.TitleWith68x68IconAndText; if (cabsNeeded.Provider.Equals("UBER")) { cabShow.Image = await StorageFile.GetFileFromApplicationUriAsync(new Uri("ms-appx:///ContosoCabs.VoiceCommandService/img/uber.png")); } else { cabShow.Image = await StorageFile.GetFileFromApplicationUriAsync(new Uri("ms-appx:///ContosoCabs.VoiceCommandService/img/ola.png")); } cabShow.AppContext = cabsNeeded; cabShow.Title = cabsNeeded.Provider; cabShow.TextLine1 = cabsNeeded.Type; cabShow.TextLine2 = "ETA : " + cabsNeeded.Eta; cabShow.TextLine3 = "Estimated Fare: " + cabsNeeded.CurrentEstimate.LowRange + "-" + cabsNeeded.CurrentEstimate.HighRange; cabTiles.Add(cabShow); var userPrompt = new VoiceCommandUserMessage(); VoiceCommandResponse response1; string source; try { source = reverse.FormattedAddress.Substring(0, reverse.FormattedAddress.IndexOf(", Hyderabad")); } catch { source = reverse.FormattedAddress; } string BookCabToDestination = "Booking " + cabsNeeded.Provider + " with " + cabsNeeded.Type + " from " + source + " to " + location + " arriving in " + cabsNeeded.Eta + cabsNeeded.CurrentEstimate.LowRange + " to " + cabsNeeded.CurrentEstimate.HighRange + " cost estimation"; userPrompt.DisplayMessage = userPrompt.SpokenMessage = BookCabToDestination; var userReprompt = new VoiceCommandUserMessage(); string confirmBookCabToDestination = "confirm booking"; userReprompt.DisplayMessage = userReprompt.SpokenMessage = confirmBookCabToDestination; response1 = VoiceCommandResponse.CreateResponseForPrompt(userPrompt, userReprompt, cabTiles); var voiceCommandConfirmation = await voiceServiceConnection.RequestConfirmationAsync(response1); if (voiceCommandConfirmation != null) { if (voiceCommandConfirmation.Confirmed == true) { BookingDetailsResponse booking = await api.BookCab(token, slat, slng); string BookCabInformation = "Cab booked. your cab driver " + booking.BookingData.DriverDetails.Name + " will be arriving shortly."; userMessage1 = new VoiceCommandUserMessage(); //userPrompt.DisplayMessage = userPrompt.SpokenMessage = BookCabInformation; userMessage.DisplayMessage = userMessage.SpokenMessage = BookCabInformation; userMessage1.DisplayMessage = userMessage1.SpokenMessage = BookCabInformation; var response = VoiceCommandResponse.CreateResponse(userMessage1, cabTiles); await voiceServiceConnection.ReportSuccessAsync(response); } else { userMessage = new VoiceCommandUserMessage(); string BookingCabToDestination = "Cancelling cab request..."; await ShowProgressScreen(BookingCabToDestination); string keepingTripToDestination = "Cancelled."; userMessage.DisplayMessage = userMessage.SpokenMessage = keepingTripToDestination; response1 = VoiceCommandResponse.CreateResponse(userMessage); await voiceServiceConnection.ReportSuccessAsync(response1); } } } }
private async Task SendCompletionMessageForBookCheapestFromXtoY(string mSource, string mDest) { string slat, slng, dlat, dlng, token, mDisplay; slat = slng = dlng = dlat = null; var mUserMessage = new VoiceCommandUserMessage(); var mUserPrompt = new VoiceCommandUserMessage(); VoiceCommandResponse mResponseError, mResponseSuccess, mResponseUserPrompt; VoiceCommandContentTile mCabTile = new VoiceCommandContentTile(); CabsAPI mCabsApi = new CabsAPI(); GeoResponse mGeoResp; Geolocator mLocator; ReverseGeoResposne mRevGeoResp; PriceEstimateResponse mPriceEstResp; BookingDetailsResponse mBookingDetailsResp; CabEstimate mCabToDisplay; List <CabEstimate> mCabEstimate; List <VoiceCommandContentTile> mCabTiles = new List <VoiceCommandContentTile>(); token = Windows.Storage.ApplicationData.Current.LocalSettings.Values["Token"].ToString(); if (mDest.Equals("")) { await ShowProgressScreen("Insufficient Info"); mDisplay = "Sorry no destination provided Please enter a valid destination"; mUserMessage.DisplayMessage = mUserMessage.SpokenMessage = mDisplay; mResponseError = VoiceCommandResponse.CreateResponse(mUserMessage); } else { mGeoResp = await mCabsApi.GeoCodingResult(token, mDest); if (mGeoResp.Code == ResponseCode.SUCCESS) { dlat = mGeoResp.Position.Latitude; dlng = mGeoResp.Position.Longitude; } else { mDisplay = "Plese enter proper Destination"; mUserMessage.DisplayMessage = mUserMessage.SpokenMessage = mDisplay; mResponseError = VoiceCommandResponse.CreateResponse(mUserMessage); await voiceServiceConnection.ReportFailureAsync(mResponseError); } } if (mSource.Equals("")) { mLocator = new Geolocator(); mLocator.DesiredAccuracyInMeters = 50; var mPosition = await mLocator.GetGeopositionAsync(); slat = mPosition.Coordinate.Point.Position.Latitude.ToString(); slng = mPosition.Coordinate.Point.Position.Longitude.ToString(); mRevGeoResp = await mCabsApi.GetReverseCodingResultlatlng(token, slat + "," + slng); if (mRevGeoResp.Code == ResponseCode.SUCCESS) { try { mSource = mRevGeoResp.FormattedAddress.Substring(0, mRevGeoResp.FormattedAddress.IndexOf(", Hyderabad")); } catch { mSource = mRevGeoResp.FormattedAddress; } } else { mDisplay = "Source not found with current location"; mUserMessage.DisplayMessage = mUserMessage.SpokenMessage = mDisplay; mResponseError = VoiceCommandResponse.CreateResponse(mUserMessage); await voiceServiceConnection.ReportFailureAsync(mResponseError); } } else { mGeoResp = await mCabsApi.GeoCodingResult(token, mSource); if (mGeoResp.Code == ResponseCode.SUCCESS) { slat = mGeoResp.Position.Latitude; slng = mGeoResp.Position.Longitude; } else { mDisplay = "Source not found"; mUserMessage.DisplayMessage = mUserMessage.SpokenMessage = mDisplay; mResponseError = VoiceCommandResponse.CreateResponse(mUserMessage); await voiceServiceConnection.ReportFailureAsync(mResponseError); } } if (slat != "" && slng != "" && dlat != "" && dlng != "") { mDisplay = "Looking for best cab providers from " + mSource.ToUpperInvariant() + " to " + mDest.ToUpperInvariant(); await ShowProgressScreen(mDisplay); mDisplay = "Booking cheapest cab from " + mSource.ToUpperInvariant() + " to " + mDest.ToUpperInvariant(); await ShowProgressScreen(mDisplay); mPriceEstResp = await mCabsApi.GetEstimate(token, slat, slng, dlat, dlng); if (mPriceEstResp.Code == ResponseCode.SUCCESS) { mCabEstimate = mPriceEstResp.Estimates; if (mCabEstimate.Count != 0) { string mDisplay1 = "Ok I have found the cheapest cab for you. Shall i book it?"; mUserPrompt.DisplayMessage = mUserPrompt.SpokenMessage = mDisplay1; mDisplay = "Shall i book it"; mUserMessage.DisplayMessage = mUserMessage.SpokenMessage = mDisplay; mCabTile.ContentTileType = VoiceCommandContentTileType.TitleWith68x68IconAndText; mCabToDisplay = mCabEstimate[0]; if (mCabToDisplay.Provider.Equals("UBER")) { mCabTile.Image = await StorageFile.GetFileFromApplicationUriAsync(new Uri("ms-appx:///ContosoCabs.VoiceCommandService/img/uber.png")); } else { mCabTile.Image = await StorageFile.GetFileFromApplicationUriAsync(new Uri("ms-appx:///ContosoCabs.VoiceCommandService/img/ola.png")); } mCabTile.Title = mCabToDisplay.Provider; mCabTile.TextLine1 = "Type : " + mCabToDisplay.Type; mCabTile.TextLine2 = "ETA : " + mCabToDisplay.Eta; mCabTile.TextLine3 = "Estimated Fare : " + mCabToDisplay.CurrentEstimate.LowRange + "-" + mCabToDisplay.CurrentEstimate.HighRange; mCabTiles.Add(mCabTile); mResponseUserPrompt = VoiceCommandResponse.CreateResponseForPrompt(mUserPrompt, mUserMessage, mCabTiles); var voiceCommandConfirmation = await voiceServiceConnection.RequestConfirmationAsync(mResponseUserPrompt); if (voiceCommandConfirmation.Confirmed) { mBookingDetailsResp = await mCabsApi.BookCab(token, slat, slng); mDisplay = "Successfully booked." + mCabToDisplay.Type + " Your cab driver " + mBookingDetailsResp.BookingData.DriverDetails.Name + " will be arriving in " + mCabToDisplay.Eta; mUserMessage.DisplayMessage = mUserMessage.SpokenMessage = mDisplay; mResponseSuccess = VoiceCommandResponse.CreateResponse(mUserMessage, mCabTiles); await voiceServiceConnection.ReportSuccessAsync(mResponseSuccess); } else { var userMessage = new VoiceCommandUserMessage(); string BookingCabToDestination = "Cancelling cab request..."; await ShowProgressScreen(BookingCabToDestination); string keepingTripToDestination = "Cancelled."; userMessage.DisplayMessage = userMessage.SpokenMessage = keepingTripToDestination; var response1 = VoiceCommandResponse.CreateResponse(userMessage); await voiceServiceConnection.ReportSuccessAsync(response1); } } else { mDisplay = "Sorry there are no cabs available right now"; mUserMessage.DisplayMessage = mUserMessage.SpokenMessage = mDisplay; mResponseError = VoiceCommandResponse.CreateResponse(mUserMessage); await voiceServiceConnection.ReportFailureAsync(mResponseError); } } } }
protected async override void OnNavigatedTo(NavigationEventArgs e) { base.OnNavigatedTo(e); if (!IsInternet()) { await new MessageDialog("Seems you are not connected to the Internet").ShowAsync(); return; } else { progress.IsActive = true; speechRecognition = e.Parameter as SpeechRecognitionResult; mSource = this.SemanticInterpretation("source", speechRecognition); mDestination = this.SemanticInterpretation("destination", speechRecognition); MyMap.MapServiceToken = "YP9WTSzOHUo0dbahsH8J~J-K6u01dT98SF4uCCKpiwA~AnGaYM6yJxoLF1tGHEIXHFskGfwSRJTr1S5aO1dB-TCXjQ1ZX0xEWgeYslbC3Fov"; Geolocator locator = new Geolocator(); locator.DesiredAccuracyInMeters = 50; var position = await locator.GetGeopositionAsync(); await MyMap.TrySetViewAsync(position.Coordinate.Point, 10D); progress.IsActive = false; // mySlider.Value = 13; CabsAPI api = new CabsAPI(); GeoResponse sResponse = await api.GeoCodingResult(Token, mSource); GeoResponse dResponse = await api.GeoCodingResult(Token, mDestination); if (sResponse.Code == ResponseCode.SUCCESS) { if (dResponse.Code == ResponseCode.SUCCESS) { AddMapIcon(Convert.ToDouble(sResponse.Position.Latitude), Convert.ToDouble(sResponse.Position.Longitude), mSource); AddMapIcon(Convert.ToDouble(dResponse.Position.Latitude), Convert.ToDouble(dResponse.Position.Longitude), mDestination); MapPolyline polyline = new MapPolyline(); var coordinates = new List <BasicGeoposition>(); var routeClient = new RouteClient(); coordinates = await routeClient.route(mSource, mDestination); polyline.StrokeColor = Windows.UI.Color.FromArgb(128, 255, 0, 0); polyline.StrokeThickness = 5; polyline.Path = new Geopath(coordinates); MyMap.MapElements.Add(polyline); SrcBox.Text = mSource; DestBox.Text = mDestination; PriceEstimateResponse pResponse = await api.GetEstimate(Token, sResponse.Position.Latitude, sResponse.Position.Longitude, dResponse.Position.Latitude, dResponse.Position.Longitude); if (pResponse.Code == ResponseCode.SUCCESS) { CabsListView.ItemsSource = pResponse.Estimates; ReadSpeech(new MediaElement(), "Showing Estimated cab fare from" + mSource + "to" + mDestination); } else { await new MessageDialog("Error in estimating cabs").ShowAsync(); return; } } else { await new MessageDialog("Destination not found").ShowAsync(); return; } } else { await new MessageDialog("Source not found").ShowAsync(); return; } } }
protected override async void OnCreate(Bundle savedInstanceState) { if (!isOnline()) { mErrorDialog.Show(); } else { for (int i = 0; i < 2; i++) { mOptions[i] = new MarkerOptions(); } base.OnCreate(savedInstanceState); SetContentView(Resource.Layout.activity_confirmed_booking); Drawable upArrow = Resources.GetDrawable(Resource.Drawable.abc_ic_ab_back_mtrl_am_alpha); upArrow.SetColorFilter(Resources.GetColor(Resource.Color.white), PorterDuff.Mode.SrcAtop); etaval = Intent.GetStringExtra("eta"); high = Intent.GetStringExtra("high"); low = Intent.GetStringExtra("low"); time = Intent.GetStringExtra("time"); sourcestring = Intent.GetStringExtra("source"); type = Intent.GetStringExtra("type"); deststring = Intent.GetStringExtra("destination"); provider = Intent.GetStringExtra("provider"); capacity = Intent.GetStringExtra("capacity"); distance = Intent.GetStringExtra("distance"); fare = Intent.GetStringExtra("fare"); mSharedPreferences = GetSharedPreferences(Constants.MY_PREF, 0); SupportActionBar.SetHomeAsUpIndicator(upArrow); SupportActionBar.SetDisplayHomeAsUpEnabled(true); token = mSharedPreferences.GetString("token", " "); mLoadingDialog = new LoadingDialog(this, Resource.Drawable.main); mLoadingDialog.SetCancelable(false); Window window = mLoadingDialog.Window; window.SetLayout(WindowManagerLayoutParams.MatchParent, WindowManagerLayoutParams.MatchParent); window.SetBackgroundDrawable(new ColorDrawable(Resources.GetColor(Resource.Color.trans))); SpannableString s = new SpannableString("Successfully Booked"); typeface = Typeface.CreateFromAsset(this.Assets, "JosefinSans-SemiBold.ttf"); s.SetSpan(new TypefaceSpan("Amaranth-Regular.ttf"), 0, s.Length(), SpanTypes.ExclusiveExclusive); s.SetSpan(new ForegroundColorSpan(this.Resources.GetColor(Resource.Color.title)), 0, s.Length(), SpanTypes.ExclusiveExclusive); this.TitleFormatted = s; mSource = FindViewById <TextView>(Resource.Id.sourcetext); mDest = FindViewById <TextView>(Resource.Id.destinationtext); eta = FindViewById <TextView>(Resource.Id.eta); dist = FindViewById <TextView>(Resource.Id.dist); price = FindViewById <TextView>(Resource.Id.price); etatext = FindViewById <TextView>(Resource.Id.etavalue); disttext = FindViewById <TextView>(Resource.Id.distvalue); pricetext = FindViewById <TextView>(Resource.Id.pricevalue); drivertext = FindViewById <TextView>(Resource.Id.drivername); cartype = FindViewById <TextView>(Resource.Id.cartype); carnumber = FindViewById <TextView>(Resource.Id.carnumber); mProvider = FindViewById <ImageView>(Resource.Id.cabprovider); mDriver = FindViewById <ImageView>(Resource.Id.driverimage); mPhone = FindViewById <ImageView>(Resource.Id.phoneimage); mPhone.SetOnClickListener(this); mSource.SetTypeface(typeface, TypefaceStyle.Normal); mDest.SetTypeface(typeface, TypefaceStyle.Normal); eta.SetTypeface(typeface, TypefaceStyle.Normal); etatext.SetTypeface(typeface, TypefaceStyle.Normal); price.SetTypeface(typeface, TypefaceStyle.Normal); pricetext.SetTypeface(typeface, TypefaceStyle.Normal); dist.SetTypeface(typeface, TypefaceStyle.Normal); disttext.SetTypeface(typeface, TypefaceStyle.Normal); drivertext.SetTypeface(typeface, TypefaceStyle.Normal); cartype.SetTypeface(typeface, TypefaceStyle.Normal); carnumber.SetTypeface(typeface, TypefaceStyle.Normal); mSource.Text = sourcestring.ToUpperInvariant(); mDest.Text = deststring.ToUpperInvariant(); etatext.Text = etaval; disttext.Text = distance; pricetext.Text = low + "-" + high; if (provider.Equals("Uber", StringComparison.InvariantCultureIgnoreCase)) { mProvider.SetImageResource(Resource.Drawable.uber); } else { mProvider.SetImageResource(Resource.Drawable.ola); } mcab = new CabsAPI(); mLoadingDialog.Show(); GeoResponse mResponse1 = await mcab.GeoCodingResult(token, sourcestring); GeoResponse mResponse2 = await mcab.GeoCodingResult(token, deststring); if (mResponse1.Code == ResponseCode.SUCCESS && mResponse2.Code == ResponseCode.SUCCESS) { slat = mResponse1.Position.Latitude.ToString(); slng = mResponse1.Position.Longitude.ToString(); dlat = mResponse2.Position.Latitude.ToString(); dlng = mResponse2.Position.Longitude.ToString(); BookingDetailsResponse mResBooking = await mcab.BookCab(token, slat, slng); if (mResBooking.Code == ResponseCode.SUCCESS) { mLoadingDialog.Dismiss(); if (provider.Equals("Uber", StringComparison.InvariantCultureIgnoreCase)) { drivertext.Text = mResBooking.BookingData.DriverDetails.Name; cartype.Text = mResBooking.BookingData.VehicleDetails.Make + " " + mResBooking.BookingData.VehicleDetails.Model; carnumber.Text = mResBooking.BookingData.VehicleDetails.License_Plate; ImageLoader.Instance.DisplayImage(mResBooking.BookingData.DriverDetails.Picture_Url, mDriver); phonenumner = mResBooking.BookingData.DriverDetails.Phone_Number; } else { phonenumner = "8110020055"; } } else { } } sourcepos = new LatLng(Convert.ToDouble(slat), Convert.ToDouble(slng)); destpos = new LatLng(Convert.ToDouble(dlat), Convert.ToDouble(dlng)); setupGoogleMap(); } }
protected override async void OnCreate(Bundle savedInstanceState) { base.OnCreate(savedInstanceState); if (!isOnline()) { mErrorDialog.Show(); } else { SetContentView(Resource.Layout.activity_confirm_details); Drawable upArrow = Resources.GetDrawable(Resource.Drawable.abc_ic_ab_back_mtrl_am_alpha); upArrow.SetColorFilter(Resources.GetColor(Resource.Color.white), PorterDuff.Mode.SrcAtop); eta = Intent.GetStringExtra("eta"); high = Intent.GetStringExtra("high"); low = Intent.GetStringExtra("low"); time = Intent.GetStringExtra("time"); sourcestring = Intent.GetStringExtra("source"); type = Intent.GetStringExtra("type"); deststring = Intent.GetStringExtra("destination"); provider = Intent.GetStringExtra("provider"); capacity = Intent.GetStringExtra("capacity"); distance = Intent.GetStringExtra("distance"); fare = Intent.GetStringExtra("fare"); mSharedPreferences = GetSharedPreferences(Constants.MY_PREF, 0); SupportActionBar.SetHomeAsUpIndicator(upArrow); SupportActionBar.SetDisplayHomeAsUpEnabled(true); token = mSharedPreferences.GetString("token", " "); mLoadingDialog = new LoadingDialog(this, Resource.Drawable.main); mLoadingDialog.SetCancelable(false); Window window = mLoadingDialog.Window; window.SetLayout(WindowManagerLayoutParams.MatchParent, WindowManagerLayoutParams.MatchParent); window.SetBackgroundDrawable(new ColorDrawable(Resources.GetColor(Resource.Color.trans))); SpannableString s = new SpannableString("Confirm Booking"); typeface = Typeface.CreateFromAsset(this.Assets, "JosefinSans-SemiBold.ttf"); s.SetSpan(new TypefaceSpan("Amaranth-Regular.ttf"), 0, s.Length(), SpanTypes.ExclusiveExclusive); s.SetSpan(new ForegroundColorSpan(this.Resources.GetColor(Resource.Color.title)), 0, s.Length(), SpanTypes.ExclusiveExclusive); this.TitleFormatted = s; mCardView = FindViewById <CardView>(Resource.Id.mapsviewcard); mConfirmButton = FindViewById <Button>(Resource.Id.btn_request); if (provider.Equals("ola", StringComparison.InvariantCultureIgnoreCase)) { mConfirmButton.SetBackgroundColor(Resources.GetColor(Resource.Color.greenola)); mConfirmButton.SetTextColor(Resources.GetColor(Resource.Color.black)); } else { mConfirmButton.SetBackgroundColor(Resources.GetColor(Resource.Color.black)); } mSource = FindViewById <TextView>(Resource.Id.sourcetext); mDest = FindViewById <TextView>(Resource.Id.destinationtext); etaText = FindViewById <TextView>(Resource.Id.etatext); etaValue = FindViewById <TextView>(Resource.Id.etavalue); distText = FindViewById <TextView>(Resource.Id.disttext); distValue = FindViewById <TextView>(Resource.Id.distvalue); priceText = FindViewById <TextView>(Resource.Id.pricetext); priceVlaue = FindViewById <TextView>(Resource.Id.pricevalue); timeText = FindViewById <TextView>(Resource.Id.timetext); timeValue = FindViewById <TextView>(Resource.Id.timevalue); mConfirmButton.SetTypeface(typeface, TypefaceStyle.Normal); mSource.SetTypeface(typeface, TypefaceStyle.Normal); mDest.SetTypeface(typeface, TypefaceStyle.Normal); etaText.SetTypeface(typeface, TypefaceStyle.Normal); etaValue.SetTypeface(typeface, TypefaceStyle.Normal); distText.SetTypeface(typeface, TypefaceStyle.Normal); distValue.SetTypeface(typeface, TypefaceStyle.Normal); priceText.SetTypeface(typeface, TypefaceStyle.Normal); priceVlaue.SetTypeface(typeface, TypefaceStyle.Normal); timeText.SetTypeface(typeface, TypefaceStyle.Normal); timeValue.SetTypeface(typeface, TypefaceStyle.Normal); mSource.Text = sourcestring; mDest.Text = deststring; etaValue.Text = eta; distValue.Text = distance; priceVlaue.Text = low + "-" + high; timeValue.Text = time; mConfirmButton.Text = "REQUEST " + type; sourcestring = mSource.Text; deststring = mDest.Text; CabsAPI api = new CabsAPI(); mLoadingDialog.Show(); GeoResponse mResponse1 = await api.GeoCodingResult(token, sourcestring); GeoResponse mResponse2 = await api.GeoCodingResult(token, deststring); if (mResponse1.Code == ResponseCode.SUCCESS && mResponse2.Code == ResponseCode.SUCCESS) { mLoadingDialog.Dismiss(); slat = mResponse1.Position.Latitude.ToString(); slng = mResponse1.Position.Longitude.ToString(); dlat = mResponse2.Position.Latitude.ToString(); dlng = mResponse2.Position.Longitude.ToString(); } sourcepos = new LatLng(Convert.ToDouble(slat), Convert.ToDouble(slng)); destpos = new LatLng(Convert.ToDouble(dlat), Convert.ToDouble(dlng)); mConfirmButton.SetOnClickListener(this); setupGoogleMap(); } }
private async Task <Arguments> ToCustomLocation(VoiceCommandActivatedEventArgs voiceCommandArgs) { string slat, dlat, slng, dlng, desiredLocation, token; GeoResponse locationResponse; CabsAPI api = new CabsAPI(); var localSettings = Windows.Storage.ApplicationData.Current.LocalSettings; token = localSettings.Values["Token"].ToString(); IReadOnlyList <string> voiceCommandPhrases; if (voiceCommandArgs.Result.SemanticInterpretation.Properties.TryGetValue("location", out voiceCommandPhrases)) { desiredLocation = voiceCommandPhrases.First(); } else { desiredLocation = ""; } Geolocator locator = new Geolocator(); locator.DesiredAccuracyInMeters = 50; var position = await locator.GetGeopositionAsync(); slat = position.Coordinate.Point.Position.Latitude.ToString(); slng = position.Coordinate.Point.Position.Longitude.ToString(); string source; ReverseGeoResposne current = await api.GetReverseCodingResultlatlng(token, position.Coordinate.Point.Position.Latitude.ToString() + "," + position.Coordinate.Point.Position.Longitude.ToString()); try { source = current.FormattedAddress.Substring(0, current.FormattedAddress.IndexOf(", Hyderabad")); } catch { source = current.FormattedAddress; } ReadSpeech(new MediaElement(), source); ReadSpeech(new MediaElement(), desiredLocation); locationResponse = await api.GeoCodingResult(token, desiredLocation); if (locationResponse.Code == ResponseCode.SUCCESS) { dlat = locationResponse.Position.Latitude; dlng = locationResponse.Position.Longitude; PriceEstimateResponse mResponseprice = await api.GetEstimate(token, slat, slng, dlat, dlng); if (mResponseprice.Code == ResponseCode.SUCCESS) { List <CabEstimate> desiredList = mResponseprice.Estimates; var sortedCabs = desiredList.OrderBy(o => o.CurrentEstimate.HighRange); Dictionary <string, object> Parameters = new Dictionary <string, object>(); Parameters.Add("location", desiredLocation); Parameters.Add("source", source); Parameters.Add("list", desiredList); Arguments data = new Arguments(null); data.AddType(VoiceCommandType.IF_FROM_APP, true); data.AddType(VoiceCommandType.BOOK_TO_CUSTOM_LOCATION, true); data.Values = Parameters; return(data); } else { await new MessageDialog("Errors fetching estimates").ShowAsync(); return(null); } } else { await new MessageDialog("Errors fetching cordinates").ShowAsync(); return(null); } }
private async Task <Arguments> ProcessBookCheapest(VoiceCommandActivatedEventArgs voiceCommandArgs) { string slat, dlat, slng, dlng, mSource, mDestination, token; GeoResponse mResponse; CabsAPI api = new CabsAPI(); var localSettings = Windows.Storage.ApplicationData.Current.LocalSettings; token = localSettings.Values["Token"].ToString(); IReadOnlyList <string> voiceCommandPhrases; if (voiceCommandArgs.Result.SemanticInterpretation.Properties.TryGetValue("source", out voiceCommandPhrases)) { mSource = voiceCommandPhrases.First(); } else { mSource = ""; } if (voiceCommandArgs.Result.SemanticInterpretation.Properties.TryGetValue("destination", out voiceCommandPhrases)) { mDestination = voiceCommandPhrases.First(); } else { mDestination = ""; } if (mSource == "") { Geolocator locator = new Geolocator(); locator.DesiredAccuracyInMeters = 50; var position = await locator.GetGeopositionAsync(); slat = position.Coordinate.Point.Position.Latitude.ToString(); slng = position.Coordinate.Point.Position.Longitude.ToString(); ReverseGeoResposne mRevResponse = await api.GetReverseCodingResultlatlng(token, position.Coordinate.Point.Position.Latitude.ToString() + "," + position.Coordinate.Point.Position.Longitude.ToString()); //mSource = mRevResponse.FormattedAddress; try { mSource = mRevResponse.FormattedAddress.Substring(0, mRevResponse.FormattedAddress.IndexOf(", Hyderabad")); } catch { mSource = mRevResponse.FormattedAddress; } System.Diagnostics.Debug.WriteLine("source is" + mSource); } else { mResponse = await api.GeoCodingResult(token, mSource); if (mResponse.Code == ResponseCode.SUCCESS) { slat = mResponse.Position.Latitude; slng = mResponse.Position.Longitude; } else { await new MessageDialog("Errors fetching source cordinates").ShowAsync(); return(null); } } if (mDestination == "") { await new MessageDialog("No Destination provided").ShowAsync(); return(null); } else { mResponse = await api.GeoCodingResult(token, mDestination); if (mResponse.Code == ResponseCode.SUCCESS) { dlat = mResponse.Position.Latitude; dlng = mResponse.Position.Longitude; PriceEstimateResponse mResponseprice = await api.GetEstimate(token, slat, slng, dlat, dlng); if (mResponseprice.Code == ResponseCode.SUCCESS) { List <CabEstimate> mList = mResponseprice.Estimates; //var sortedCabs = mList.OrderBy(o => o.AverageEstimate); Dictionary <string, object> Parameters = new Dictionary <string, object>(); Parameters.Add("source", mSource); Parameters.Add("destination", mDestination); Parameters.Add("list", mList); Arguments data = new Arguments(null); data.AddType(VoiceCommandType.IF_FROM_APP, true); data.AddType(VoiceCommandType.BOOK_CHEAPEST_TO_DEST, true); data.AddType(VoiceCommandType.BOOK_ME_CHEAPEST_CAB_FROM_X_TO_Y, true); data.Values = Parameters; return(data); } else { await new MessageDialog("Error fetching estimaates").ShowAsync(); return(null); } } else { await new MessageDialog("Error retrieving Destination cordinates").ShowAsync(); return(null); } } }
public async void init(View rootView) { if (!isOnline()) { mErrorDialog.Show(); return; } api = new CabsAPI(); mLoadingDialog = new LoadingDialog(mActivity, Resource.Drawable.main); mLoadingDialog.SetCancelable(false); Window window = mLoadingDialog.Window; window.SetLayout(WindowManagerLayoutParams.MatchParent, WindowManagerLayoutParams.MatchParent); window.SetBackgroundDrawable(new ColorDrawable(Resources.GetColor(Resource.Color.trans))); SpannableString s = new SpannableString("Home"); typeface = Typeface.CreateFromAsset(mActivity.Assets, "JosefinSans-SemiBold.ttf"); s.SetSpan(new TypefaceSpan("Amaranth-Regular.ttf"), 0, s.Length(), SpanTypes.ExclusiveExclusive); s.SetSpan(new ForegroundColorSpan(this.Resources.GetColor(Resource.Color.title)), 0, s.Length(), SpanTypes.ExclusiveExclusive); mActivity.TitleFormatted = s; mSharedPreference = mActivity.GetSharedPreferences(Constants.MY_PREF, 0); token = mSharedPreference.GetString("token", " "); if (mActivity.Intent.GetStringExtra("source") != null) { msourceRecieved = mActivity.Intent.GetStringExtra("source"); } else { msourceRecieved = mSharedPreference.GetString("source", "1,ISB Rd,Gachibowli"); } autoSourceBox = rootView.FindViewById <AppCompatAutoCompleteTextView>(Resource.Id.sourceauto); autoSourceBox.Text = msourceRecieved; sourceSuggestionsAdapter = new SearchSuggestionsAdapter(mActivity); autoSourceBox.Adapter = sourceSuggestionsAdapter; destinationSuggestionsAdapter = new SearchSuggestionsAdapter(mActivity); autoSourceBox.ItemClick += mSourceTextBoxClicked; autoDestinationBox = rootView.FindViewById <AppCompatAutoCompleteTextView>(Resource.Id.destinationauto); autoDestinationBox.Adapter = destinationSuggestionsAdapter; autoDestinationBox.ItemClick += mDestinationTextBoxClicked; mLoadingDialog.Show(); mRecyclerView = rootView.FindViewById <RecyclerView>(Resource.Id.cabrecycler); LinearLayoutManager linearLayoutManager = new LinearLayoutManager(Application.Context); mRecyclerView.SetLayoutManager(linearLayoutManager); mRecyclerView.AddItemDecoration(new VerticalSpaceItemDecoration(VERTICAL_ITEM_SPACE)); LayoutInflater inflater = (LayoutInflater)Activity.GetSystemService(Context.LayoutInflaterService); View Childlayout = inflater.Inflate(Resource.Layout.fragment_google_maps, null); if (msourceRecieved != null) { GeoResponse mResponseGetSourcelatlng = await api.GeoCodingResult(token, msourceRecieved); slat = mResponseGetSourcelatlng.Position.Latitude; slng = mResponseGetSourcelatlng.Position.Longitude; hasSourceSet = false; setSourceMarker(msourceRecieved); } CabsResponse response = await api.GetNearbyCabs(slat, slng, Constants.AUTH_TOKEN); if (response.Code == ResponseCode.SUCCESS) { mCabs = response.Cabs; mAdapter = new CabRecyclerAdapter(Application.Context, mCabs, mActivity); mAdapter.ItemClick += OnItemClick; mRecyclerView.SetAdapter(mAdapter); mLoadingDialog.Dismiss(); } }
protected async override void OnNavigatedTo(NavigationEventArgs e) { base.OnNavigatedTo(e); if (!IsInternet()) { await new MessageDialog("Seems you are not connected to the Internet").ShowAsync(); return; } else { progress.IsActive = true; MyMap.MapServiceToken = "YP9WTSzOHUo0dbahsH8J~J-K6u01dT98SF4uCCKpiwA~AnGaYM6yJxoLF1tGHEIXHFskGfwSRJTr1S5aO1dB-TCXjQ1ZX0xEWgeYslbC3Fov"; Geolocator locator = new Geolocator(); locator.DesiredAccuracyInMeters = 50; var position = await locator.GetGeopositionAsync(); await MyMap.TrySetViewAsync(position.Coordinate.Point, 17D); progress.IsActive = false; mySlider.Value = 13; Arguments args = e.Parameter as Arguments; Dictionary <string, object> Parameters = args.Values; if (args.GetType(VoiceCommandType.NO_VOICE)) { mSource = Parameters["source"].ToString(); mDestination = Parameters["destination"].ToString(); CabsAPI api = new CabsAPI(); GeoResponse sResponse = await api.GeoCodingResult(Token, mSource); GeoResponse dResponse = await api.GeoCodingResult(Token, mDestination); if (sResponse.Code == ResponseCode.SUCCESS && dResponse.Code == ResponseCode.SUCCESS) { AddMapIcon(Convert.ToDouble(sResponse.Position.Latitude), Convert.ToDouble(sResponse.Position.Longitude), mSource); AddMapIcon(Convert.ToDouble(dResponse.Position.Latitude), Convert.ToDouble(dResponse.Position.Longitude), mDestination); } else { await new MessageDialog("Error retrieving Geopositions!").ShowAsync(); return; } MapPolyline polyline = new MapPolyline(); var coordinates = new List <BasicGeoposition>(); var routeClient = new RouteClient(); coordinates = await routeClient.route(mSource, mDestination); polyline.StrokeColor = Windows.UI.Color.FromArgb(128, 255, 0, 0); polyline.StrokeThickness = 5; polyline.Path = new Geopath(coordinates); MyMap.MapElements.Add(polyline); SrcBox.Text = mSource; DestBox.Text = mDestination; PriceEstimateResponse pResponse = await api.GetEstimate(Token, Parameters["slat"].ToString(), Parameters["slng"].ToString(), Parameters["dlat"].ToString(), Parameters["dlng"].ToString()); if (pResponse.Code == ResponseCode.SUCCESS) { CabsListView.ItemsSource = pResponse.Estimates; // ReadSpeech(new MediaElement(), "Showing Estimated cab fare from" + mSource + "to" + mDestination); } } } }
protected async override void OnNavigatedTo(NavigationEventArgs e) { base.OnNavigatedTo(e); ShowLoader(true); { if (!IsInternet()) { await new MessageDialog("Seems you are not connected to the Internet").ShowAsync(); return; } else { MyMap.MapServiceToken = "YP9WTSzOHUo0dbahsH8J~J-K6u01dT98SF4uCCKpiwA~AnGaYM6yJxoLF1tGHEIXHFskGfwSRJTr1S5aO1dB-TCXjQ1ZX0xEWgeYslbC3Fov"; Geolocator locator = new Geolocator(); locator.DesiredAccuracyInMeters = 50; var position = await locator.GetGeopositionAsync(); await MyMap.TrySetViewAsync(position.Coordinate.Point, 10D); //mySlider.Value = 13; Arguments args = e.Parameter as Arguments; if (args.GetType(VoiceCommandType.BOOK_CHEAPEST_TO_DEST)) { string source = args.Values["source"].ToString(); string destination = args.Values["destination"].ToString(); CabsAPI api = new CabsAPI(); string token = Windows.Storage.ApplicationData.Current.LocalSettings.Values["Token"].ToString(); GeoResponse sResponse = await api.GeoCodingResult(token, source.ToLower()); GeoResponse dResponse = await api.GeoCodingResult(token, destination.ToLower()); if (dResponse.Code == ResponseCode.SUCCESS) { if (sResponse.Code == ResponseCode.SUCCESS) { Addroute(sResponse, dResponse, source, destination); Dictionary <string, object> Parameters = args.Values; List <CabEstimate> mCabs = new List <CabEstimate>(); mCabs = Parameters["list"] as List <CabEstimate>; ETAData.Text = mCabs[0].Eta; PriceData.Text = mCabs[0].CurrentEstimate.LowRange + "-" + mCabs[0].CurrentEstimate.HighRange; DistanceData.Text = mCabs[0].CurrentEstimate.Distance; TimeData.Text = mCabs[0].CurrentEstimate.Time; if (Parameters["source"] != null) { if (Parameters["source"].ToString() == null) { SrcBox.Text = "Microsoft Building 1 ".ToUpperInvariant(); } else { SrcBox.Text = Parameters["source"].ToString().ToUpperInvariant(); } } if (Parameters["destination"] != null) { DestBox.Text = Parameters["destination"].ToString().ToUpperInvariant(); } } else { await new MessageDialog("Error retrieving Geoposition").ShowAsync(); return; } } else { await new MessageDialog("Destiantion not found.").ShowAsync(); return; } } else if (args.GetType(VoiceCommandType.NO_VOICE)) { Dictionary <string, object> Parameters = args.Values; string source = Parameters["source"].ToString(); string destination = Parameters["destination"].ToString(); CabsAPI apiCus = new CabsAPI(); string tokenCus = Windows.Storage.ApplicationData.Current.LocalSettings.Values["Token"].ToString(); GeoResponse sResponse = await apiCus.GeoCodingResult(tokenCus, source.ToLower()); GeoResponse dResponse = await apiCus.GeoCodingResult(tokenCus, destination.ToLower()); Addroute(sResponse, dResponse, source, destination); ETAData.Text = Parameters["eta"].ToString(); PriceData.Text = Parameters["price"].ToString(); DistanceData.Text = Parameters["distance"].ToString(); TimeData.Text = Parameters["time"].ToString(); SrcBox.Text = Parameters["source"].ToString().ToUpperInvariant(); DestBox.Text = Parameters["destination"].ToString().ToUpperInvariant(); } else if (args.GetType(VoiceCommandType.BOOK_TO_CUSTOM_LOCATION)) { string source = args.Values["source"].ToString(); string destination = args.Values["location"].ToString(); CabsAPI apiCus = new CabsAPI(); string tokenCus = Windows.Storage.ApplicationData.Current.LocalSettings.Values["Token"].ToString(); GeoResponse sResponse = await apiCus.GeoCodingResult(tokenCus, source.ToLower()); GeoResponse dResponse = await apiCus.GeoCodingResult(tokenCus, destination.ToLower()); if (sResponse.Code == ResponseCode.SUCCESS) { if (dResponse.Code == ResponseCode.SUCCESS) { Addroute(sResponse, dResponse, source, destination); Dictionary <string, object> Parameters = args.Values; List <CabEstimate> DesiredCabs = new List <CabEstimate>(); DesiredCabs = Parameters["list"] as List <CabEstimate>; ETAData.Text = DesiredCabs[0].Eta; PriceData.Text = DesiredCabs[0].CurrentEstimate.LowRange + "-" + DesiredCabs[0].CurrentEstimate.HighRange; DistanceData.Text = DesiredCabs[0].CurrentEstimate.Distance; TimeData.Text = DesiredCabs[0].CurrentEstimate.Time; SrcBox.Text = "Microsoft Building 1 Gachibowli Hyderabad".ToUpperInvariant(); if (Parameters["location"] != null) { DestBox.Text = Parameters["location"].ToString().ToUpperInvariant(); } } else { await new MessageDialog("Destination not found.").ShowAsync(); return; } } else { await new MessageDialog("Error retrieving Geoposition").ShowAsync(); return; } } else if (args.GetType(VoiceCommandType.BOOK_ME_A_CAB_FROM_X_TO_Y)) { string source = args.Values["source"].ToString(); string destination = args.Values["destination"].ToString(); CabsAPI api = new CabsAPI(); string token = Windows.Storage.ApplicationData.Current.LocalSettings.Values["Token"].ToString(); PlacesResponse sResponse = await api.GetPlaceLocation(source.ToLower(), token); PlacesResponse dResponse = await api.GetPlaceLocation(destination.ToLower(), token); if (sResponse.Code == ResponseCode.SUCCESS) { if (dResponse.Code == ResponseCode.SUCCESS) { Addroute(sResponse, dResponse, source, destination); //AddMapIcon(Convert.ToDouble(sResponse.Location.Latitude), Convert.ToDouble(sResponse.Location.Longitude), source); //AddMapIcon(Convert.ToDouble(dResponse.Location.Latitude), Convert.ToDouble(dResponse.Location.Longitude), destination); //MapPolyline polyline = new MapPolyline(); //var coordinates = new List<BasicGeoposition>(); //var routeClient = new RouteClient(); //string sourceLoc = sResponse.Location.Latitude + "," + sResponse.Location.Longitude; //string destinationLoc = dResponse.Location.Latitude + "," + dResponse.Location.Longitude; //coordinates = await routeClient.route(sourceLoc, destinationLoc); //polyline.StrokeColor = Windows.UI.Color.FromArgb(128, 255, 0, 0); //polyline.StrokeThickness = 5; //polyline.Path = new Geopath(coordinates); //MyMap.MapElements.Add(polyline); //ReadSpeech(new MediaElement(), sResponse.Location.Latitude + " ok " + dResponse.Location.Longitude); PriceEstimateResponse pRespone = await api.GetEstimate(token, sResponse.Location.Latitude, sResponse.Location.Longitude, dResponse.Location.Latitude, dResponse.Location.Longitude); //ReadSpeech(new MediaElement(), pRespone.Estimates.First().Provider); SrcBox.Text = source; DestBox.Text = destination; //AddMapIcon(sResponse.Location.Latitude,) if (pRespone.Code == ResponseCode.SUCCESS) { ETAData.Text = pRespone.Estimates[1].Eta; PriceData.Text = pRespone.Estimates[1].CurrentEstimate.LowRange + "-" + pRespone.Estimates[1].CurrentEstimate.HighRange; DistanceData.Text = pRespone.Estimates[1].CurrentEstimate.Distance; TimeData.Text = pRespone.Estimates[1].CurrentEstimate.Time; } else { await new MessageDialog("Error in estimating prices").ShowAsync(); return; } } else { await new MessageDialog("Destination not found").ShowAsync(); return; } } else { await new MessageDialog("Error retrieving Geoposition").ShowAsync(); return; } } else if (args.GetType(VoiceCommandType.ESTIMATE_FROM)) { string source = args.Values["source"].ToString(); string destination = args.Values["destination"].ToString(); CabsAPI apiCus = new CabsAPI(); string token = Windows.Storage.ApplicationData.Current.LocalSettings.Values["Token"].ToString(); GeoResponse sResponse = await apiCus.GeoCodingResult(token, source.ToLower()); GeoResponse dResponse = await apiCus.GeoCodingResult(token, destination.ToLower()); Addroute(sResponse, dResponse, source, destination); Arguments eArgs = args as Arguments; SrcBox.Text = source; DestBox.Text = destination; ETAData.Text = eArgs.Values["eta"].ToString(); PriceData.Text = eArgs.Values["low"].ToString() + "-" + eArgs.Values["high"].ToString(); DistanceData.Text = eArgs.Values["distance"].ToString(); TimeData.Text = eArgs.Values["time"].ToString(); } } } ShowLoader(false); }
protected async override void OnNavigatedTo(NavigationEventArgs e) { base.OnNavigatedTo(e); if (!IsInternet()) { await new MessageDialog("Seems you are not connected to the Internet").ShowAsync(); return; } else { progress.IsActive = true; speechRecognition = e.Parameter as SpeechRecognitionResult; if (speechRecognition != null) { mSource = this.SemanticInterpretation("source", speechRecognition); mDestination = this.SemanticInterpretation("destination", speechRecognition); if (mSource != null) { SearchSourceBox.Text = mSource; } if (mDestination != null) { SearchDestinationBox.Text = mDestination; } } try { var parameter = e.Parameter as WwwFormUrlDecoder; _destination = parameter.GetFirstValueByName("nmlocation"); if (_destination == null || _destination.Equals("")) { _destination = "Gachibowli"; } System.Diagnostics.Debug.WriteLine(_destination); _isFromInsight = true; } catch (Exception) { } finally { MyMap.MapServiceToken = "YP9WTSzOHUo0dbahsH8J~J-K6u01dT98SF4uCCKpiwA~AnGaYM6yJxoLF1tGHEIXHFskGfwSRJTr1S5aO1dB-TCXjQ1ZX0xEWgeYslbC3Fov"; Geolocator locator = new Geolocator(); locator.DesiredAccuracyInMeters = 50; position = await locator.GetGeopositionAsync(); await MyMap.TrySetViewAsync(position.Coordinate.Point, 17D); progress.IsActive = false; mySlider.Value = MyMap.ZoomLevel; AddMapIcon(position.Coordinate.Point.Position.Latitude, position.Coordinate.Point.Position.Longitude); CabsAPI api = new CabsAPI(); latlng = position.Coordinate.Point.Position.Latitude.ToString() + "," + position.Coordinate.Point.Position.Longitude.ToString(); ReverseGeoResposne res = await api.GetReverseCodingResultlatlng(Token, latlng); if (res.Code == ResponseCode.SUCCESS) { CurrentSource = res.FormattedAddress; SearchSourceBox.Text = CurrentSource; _source = CurrentSource; string lat = position.Coordinate.Point.Position.Latitude.ToString(); string lng = position.Coordinate.Point.Position.Longitude.ToString(); _cabsView = new CabsListViewModel(lng, lat, Token); latlng = position.Coordinate.Point.Position.Latitude.ToString() + "," + position.Coordinate.Point.Position.Longitude.ToString(); if (_isFromInsight) { SearchDestinationBox.Text = _destination; GeoResponse location; var localSettings = Windows.Storage.ApplicationData.Current.LocalSettings; token = localSettings.Values["Token"].ToString(); location = await api.GeoCodingResult(token, _destination); if (location.Code == ResponseCode.SUCCESS) { dlat = location.Position.Latitude; dlng = location.Position.Longitude; AddMapIcon(double.Parse(dlat), double.Parse(dlng)); _cabsView.SetLatLng(dlat, dlng); ShowLoader(true); await _cabsView.RefreshView(CabsListViewModel.REFRESH_ESTIMATE); CabsListView.ItemsSource = _cabsView.Cabs; ShowLoader(false); } else { await new MessageDialog("Error fetching coordinates").ShowAsync(); } } else { ShowLoader(true); await _cabsView.RefreshView(CabsListViewModel.REFRESH_SURGE); CabsListView.ItemsSource = _cabsView.Cabs; ShowLoader(false); } } else { await new MessageDialog("No such location exists").ShowAsync(); } } } }