public static string getPrice(LatLong start, LatLong end)
 {
     if (start != null && end != null)
     {
         string URL           = "https://api.uber.com/v1";
         string urlParameters = "/estimates/price?" +
                                "start_latitude=" + start.Latitude +
                                "&start_longitude=" + start.Longitude +
                                "&end_latitude=" + end.Latitude +
                                "&end_longitude=" + end.Longitude;
         string data = API_Call(URL, urlParameters);
         return(data);
     }
     else
     {
         return(null);
     }
 }
        public static void ScrapData(string Area)
        {
            Console.WriteLine("******Thread is Started for " + Area + "******");
            try
            {
                while (true)
                {
                    foreach (var item in Area.Equals("Boston") ? array.Boston : array.Cambridge)
                    {
                        LatLong SourceLatLong = LatLongServices.GeocodeAddress(Convert.ToString(item.Area) + " MA");
                        if (SourceLatLong != null)
                        {
                            for (double i = 3218.69; i <= 9656.06; i = i + 3218.69)
                            {
                                try
                                {
                                    LatLong EndlatLong = LatLongServices.CalculateDerivedPosition(SourceLatLong, i, 0);
                                    string  Price      = UberServices.getPrice(SourceLatLong, EndlatLong);
                                    DbServices.addData(Price, SourceLatLong, EndlatLong, (i / 1609.34).ToString());
                                    Console.WriteLine("====Area: " + item.Area + ", Distance: " + i + "\nStartLatLong: " + SourceLatLong.Latitude + ", " + SourceLatLong.Longitude + " EndLatLong: " + EndlatLong.Latitude + ", " + EndlatLong.Longitude + " ====");

                                    Thread.Sleep(1000);
                                }
                                catch (Exception ex)
                                {
                                    Console.WriteLine(ex.Message);
                                    Console.WriteLine("%%%%%%Error Occurred in Writing Data to Mongo%%%%%%");
                                }
                            }
                        }
                    }
                    Console.WriteLine("******Thread is in Sleep Mode*******");
                    Thread.Sleep(49500);
                }
            }
            catch (Exception ex) {
                Console.WriteLine("%%%%Error Occurred in Running Thread%%%%%");
                Console.WriteLine(ex.Message);
            }
        }
Esempio n. 3
0
        public static LatLong CalculateDerivedPosition(LatLong source, double range, double bearing)
        {
            try
            {
                double latA = source.Latitude * DegreesToRadians;
                double lonA = source.Longitude * DegreesToRadians;
                double angularDistance = range / EarthRadius;
                double trueCourse = bearing * DegreesToRadians;

                double lat = Math.Asin(Math.Sin(latA) * Math.Cos(angularDistance) + Math.Cos(latA) * Math.Sin(angularDistance) * Math.Cos(trueCourse));

                double dlon = Math.Atan2(Math.Sin(trueCourse) * Math.Sin(angularDistance) * Math.Cos(latA), Math.Cos(angularDistance) - Math.Sin(latA) * Math.Sin(lat));
                double lon = ((lonA + dlon + Math.PI) % (Math.PI * 2)) - Math.PI;

                return new LatLong(lat * RadiansToDegrees, lon * RadiansToDegrees);
            }
            catch (Exception ex)
            {
                Console.WriteLine("%%%%%Error Occurred in Calculating Derived Position %%%%%%");
                Console.WriteLine(ex.Message);
                return source;
            }
        }