void getCoordinates() { try { reference.GetValueAsync().ContinueWith(task => { if (task.IsFaulted) { throw new Exception("ERROR while fetching data from database!!! Please refresh scene(Click Tours)"); } else if (task.IsCompleted) { DataSnapshot snapshot = task.Result.Child(dbDetails.getBuildingDBname()); string str = snapshot.GetRawJsonValue(); JObject jsonLocation = JObject.Parse(str); for (int i = 1; i < locations.Count; i++) { TourLocation location = (TourLocation)locations[i]; if (sharedLocations.ContainsKey(location.Name)) { location.Latitute = sharedLocations[location.Name].Latitude; location.Longitude = sharedLocations[location.Name].Longitude; } else { location.Latitute = (string)jsonLocation[location.Name]["Coordinates"]["Latitude"]; location.Longitude = (string)jsonLocation[location.Name]["Coordinates"]["Longitude"]; } double lat = double.Parse(location.Latitute); double lon = double.Parse(location.Longitude); coordinates.Add(new Vector2d(lat, lon)); } } }); } catch (InvalidCastException e) { // Perform some action here, and then throw a new exception. ErrorMessage.text = e.Message; ErrorPanel.SetActive(true); } catch (Exception e) { // Perform some action here, and then throw a new exception. ErrorMessage.text = e.Message; ErrorPanel.SetActive(true); } }
public void getCoordinates() { try { if (Hours.text == "hour" || Minutes.text == "minute") { ErrorPanel.transform.SetAsLastSibling(); throw new Exception("Please enter time"); } if (locationToggle.isOn) { GetCurrentLocation(); } else { if (location.text == "") { ErrorPanel.transform.SetAsLastSibling(); throw new Exception("Please enter location!"); } reference.GetValueAsync().ContinueWith(task => { // if (task.IsFaulted) // { // ErrorPanel.transform.SetAsLastSibling(); // throw new Exception("ERROR while fetching data from database!!! Please refresh!"); // } if (task.IsCompleted) { DataSnapshot snapshot = task.Result.Child(dbDetails.getBuildingDBname()); string str = snapshot.GetRawJsonValue(); JObject jsonLocation = JObject.Parse(str); var locationText = location.text; lat = (string)jsonLocation[locationText]["Coordinates"]["Latitude"]; lon = (string)jsonLocation[locationText]["Coordinates"]["Longitude"]; } }); } if (lat != null && lon != null) { locationLink.text = lat + ":" + lon + ":" + Hours.text + ":" + Minutes.text; } } catch (InvalidCastException e) { Debug.Log(e.Message); // Perform some action here, and then throw a new exception. ErrorMessage.text = e.Message; ErrorPanel.SetActive(true); } catch (Exception e) { Debug.Log(e.Message); // Perform some action here, and then throw a new exception. ErrorMessage.text = e.Message; ErrorPanel.SetActive(true); } }