コード例 #1
0
        private double GetDistance(AirportInfoModel firstAirport, AirportInfoModel secondAirport, string returnValType = Constants.Mile)
        {
            try
            {
                GeoCoordinate pin1 = new GeoCoordinate(firstAirport.Location.Latitude, firstAirport.Location.Longitude);
                GeoCoordinate pin2 = new GeoCoordinate(secondAirport.Location.Latitude, secondAirport.Location.Longitude);

                //default return type is meter from GetDistanceTo.
                double measuredDistance = pin1.GetDistanceTo(pin2);
                if (measuredDistance != 0)
                {
                    measuredDistance = measuredDistance / 1000; // convert to km.
                }
                else
                {
                    return(0);
                }

                if (returnValType != Constants.Kilometer)
                {
                    return(measuredDistance.ConvertKilometersToMiles());
                }
                return(measuredDistance);
            }
            catch (Exception ex)
            {
                throw new Exception("An error is occured while calculating measure.");
            }
        }
コード例 #2
0
        private async Task <AirportInfoModel> GetAirportInfoAsync(string airportCode)
        {
            AirportInfoModel airportInfo = new AirportInfoModel();
            var    response = string.Empty;
            string endPoint = $"{_appSettings.TelePortDevUrl}{airportCode.ToUpper(new CultureInfo("en-US", false))}";

            using (var client = new HttpClient())
            {
                HttpResponseMessage result = await client.GetAsync(endPoint);

                if (result.IsSuccessStatusCode)
                {
                    response = await result.Content.ReadAsStringAsync();

                    airportInfo = Newtonsoft.Json.JsonConvert.DeserializeObject <AirportInfoModel>(response);
                }
                else
                {
                    throw new Exception("An error is occured while fetching airport info. Please check airport IATA code.");
                }
            }
            return(airportInfo);
        }