private void holdWhere(object sender, System.Windows.Input.GestureEventArgs e) { //Moq //holdWhereMoq(); //return; if (NetworkInterface.GetIsNetworkAvailable()) { Thread thread = new Thread(new ThreadStart((Action)(() => { try { SpeechSynthesizer speech = new SpeechSynthesizer("SmartAudioCityGuide", "Lz+vYpOFm6NTP83A9y0tPoX6ByJa06Q6yxHvoBsD0xo="); Routes routesServices = new Routes(Properties.getServerIP()); MyGPS gps = new MyGPS(); CultureInfo culture = new CultureInfo("en-US"); double currentLatitude = gps.actualLocation.Position.Location.Latitude; double currentLongitude = gps.actualLocation.Position.Location.Longitude; int esc = 60; routesServices.getAddressFromCoordinates(currentLatitude.ToString(culture) + "," + currentLongitude.ToString(culture)); while (routesServices.routeDone == false && esc > 0) { Thread.Sleep(70); esc--; } if (routesServices.country == null || routesServices.city == null || esc < 0) { sound.play("error"); return; } speech.SpeakAsync(routesServices.street, CultureInfo.CurrentCulture.ToString()); } catch (Exception) { } }))); thread.Start(); } else { sound.play("internet"); } }
private void getRoute() { Routes routesServices = new Routes(Properties.getServerIP()); SpeechSynthesizer speech = new SpeechSynthesizer("SmartAudioCityGuide", "Lz+vYpOFm6NTP83A9y0tPoX6ByJa06Q6yxHvoBsD0xo="); MyGPS gps = new MyGPS(); CultureInfo culture = new CultureInfo("en-US"); double dist,mindist; string orientation; double destLat = (Application.Current as App).latShared; double destLon = (Application.Current as App).lonShared; int cont = 0; thread = new Thread(new ThreadStart((Action)(() => { try { do { orientation = gps.actualLocation.Position.Location.Course.ToString(culture); if (orientation == "NaN") orientation = "0"; currentLatitude = gps.actualLocation.Position.Location.Latitude; currentLongitude = gps.actualLocation.Position.Location.Longitude; routesServices.getAddressFromCoordinates(currentLatitude.ToString(culture) + "," + currentLongitude.ToString(culture)); while (routesServices.routeDone == false && cont < 100) { cont++; Thread.Sleep(70); } if (routesServices.country == null || routesServices.city == null) { error(); return; } cont = 0; routesServices.Route(currentLatitude.ToString(culture) + "," + currentLongitude.ToString(culture) + ";" + destLat.ToString(culture) + "," + destLon.ToString(culture) + " ; " + orientation + " ; " + CultureInfo.CurrentCulture.TwoLetterISOLanguageName); while (routesServices.routeDone == false && cont<100) { cont++; Thread.Sleep(70); } if (routesServices.route == null) { error(); return; } routes = routesServices.route; dist = distance(routesServices.route[0].lat, routesServices.route[0].lon); mindist = dist; while (((mindist + epsilon) > dist) && routes.Count > 0 && endThread == false) { currentLatitude = gps.actualLocation.Position.Location.Latitude; currentLongitude = gps.actualLocation.Position.Location.Longitude; dist = distance(routesServices.route[0].lat, routesServices.route[0].lon); if (mindist > dist) mindist = dist; routesServices.getAddressFromCoordinates(currentLatitude.ToString(culture) + "," + currentLongitude.ToString(culture)); if (dist < epsilon) { routesServices.route.RemoveAt(0); if (routesServices.route.Count > 0) { dist = distance(routesServices.route[0].lat, routesServices.route[0].lon); mindist = dist; } if (routesServices.route.Count == 0) { sound.play("success"); Deployment.Current.Dispatcher.BeginInvoke(() => { NavigationService.GoBack(); } ); return; } } /* Threads comuns nao podem alterar a UI, entao é necessario criar o evento como a thread de UI */ if (endThread == false) { Deployment.Current.Dispatcher.BeginInvoke(() => { OnChanged(EventArgs.Empty); } ); speech.SpeakAsync(routesServices.street + ". " + routesServices.route[0].description + ". In " + Convert.ToInt32(dist).ToString() + " meters", CultureInfo.CurrentCulture.ToString()); Thread.Sleep(15000); } } } while (routes.Count > 0 && endThread == false); if (endThread == false) { Deployment.Current.Dispatcher.BeginInvoke(() => { sound.play("success"); System.Threading.Thread.Sleep(750); sound.play("selectlocation"); NavigationService.GoBack(); } ); return; } } /* Mandar mensagem de erro e voltar para pagina anterior */ catch (Exception) { if(endThread == false) error(); return; } }))); thread.Start(); }