Esempio n. 1
0
 /// <summary>
 /// If the response status indicates fail because of quota exceeded - mark test as inconclusive.
 /// </summary>
 public static void NotExceedQuota(ElevationResponse response)
 {
     if (response?.Status == Entities.Elevation.Response.Status.OVER_QUERY_LIMIT)
     {
         throw new InconclusiveException(QuotaExceedMessage);
     }
 }
        private void map_OnMapDrag()
        {
            Task.Run(() =>
            {
                var elevationRequest = new ElevationRequest()
                {
                    Locations = new[] { new Location(map.Position.Lat, map.Position.Lng) },
                };
                try
                {
                    ElevationResponse elevation = GoogleMaps.Elevation.Query(elevationRequest);
                    if (elevation.Status == Status.OK)
                    {
                        foreach (Result result in elevation.Results)
                        {
                            SetText(result.Elevation);
                        }
                    }
                }
                catch (Exception)
                {
                    // ignored
                }
            });

            textBox1.Text = map.Position.Lat.ToString(CultureInfo.InvariantCulture);
            textBox2.Text = map.Position.Lng.ToString(CultureInfo.InvariantCulture);
        }
Esempio n. 3
0
 private void map_OnMapDrag()
 {
     Task.Run(() =>
     {
         WebClient request = new WebClient();
         ElevationRequest elevationRequest = new ElevationRequest()
         {
             Locations = new Location[] { new Location(map.Position.Lat, map.Position.Lng) },
         };
         try
         {
             ElevationResponse elevation = GoogleMaps.Elevation.Query(elevationRequest);
             if (elevation.Status == Status.OK)
             {
                 foreach (Result result in elevation.Results)
                 {
                     SetText(result.Elevation);
                 }
             }
         }
         catch (Exception ex)
         {
         }
     });
     textBox1.Text = map.Position.Lat.ToString();
     textBox2.Text = map.Position.Lng.ToString();
 }
Esempio n. 4
0
        private void map_OnMapDrag()
        {
            Task.Run(() =>
            {
                var elevationRequest = new ElevationRequest()
                {
                    Locations = new[] { new Location(map.Position.Lat, map.Position.Lng) },
                };
                try
                {
                    ElevationResponse elevation = GoogleMaps.Elevation.Query(elevationRequest);
                    if (elevation.Status == Status.OK)
                    {
                        foreach (Result result in elevation.Results)
                        {
                            try
                            {
                                SetText(result.Elevation);
                            }
                            catch (Exception e)
                            {
                                Logger.ColoredConsoleWrite(ConsoleColor.Red, "Error: LocationPanel.cs - Zeile 653.");
                                Logger.ColoredConsoleWrite(ConsoleColor.Red, e.Message);
                            }
                        }
                    }
                }
                catch (Exception)
                {
                    // ignored
                }
            });

            textBox1.Text = map.Position.Lat.ToString(CultureInfo.InvariantCulture);
            textBox2.Text = map.Position.Lng.ToString(CultureInfo.InvariantCulture);

            if (radiusOverlay != null)
            {
                radiusOverlay.Polygons.Clear();
                radiusOverlay.Polygons.Add(CreateCircle(new PointLatLng(map.Position.Lat, map.Position.Lng), (int)nudRadius.Value, 100));
            }
        }
Esempio n. 5
0
        public static double GetAltitudeWithKEY(double lat, double lng, string key)
        {
            var elevationRequest = new ElevationRequest {
                Locations = new[] { new Location(lat, lng) },
            };

            elevationRequest.ApiKey = key;
            try {
                ElevationResponse elevation = GoogleMaps.Elevation.Query(elevationRequest);
                if (elevation.Status == Status.OK)
                {
                    foreach (Result result in elevation.Results)
                    {
                        return(result.Elevation);
                    }
                }
            } catch (Exception ex1) {
                Logger.ExceptionInfo(ex1.ToString());
            }
            return(GetRandom(11.0d, 8.6d));
        }
Esempio n. 6
0
        void ButtonSetLocationClick(object sender, EventArgs e)
        {
            double lat = Globals.latitute;
            double lng = Globals.longitude;

            try
            {
                lat = double.Parse(textBoxLatitude.Text.Replace(',', '.'), GUI.cords, System.Globalization.NumberFormatInfo.InvariantInfo);
                if (lat > 90.0 || lat < -90.0)
                {
                    throw new System.ArgumentException("Value has to be between 90 and -90!");
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
                textBoxLatitude.Text = "";
            }
            try
            {
                lng = double.Parse(textBoxLongitude.Text.Replace(',', '.'), GUI.cords, System.Globalization.NumberFormatInfo.InvariantInfo);
                if (lng > 180.0 || lng < -180.0)
                {
                    throw new System.ArgumentException("Value has to be between 180 and -180!");
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
                textBoxLongitude.Text = "";
            }
            if (lat != Globals.latitute && lng != Globals.longitude)
            {
                if ((!lat.Equals(Globals.latitute)) && (!lng.Equals(Globals.longitude)))
                {
                    Globals.latitute  = lat;
                    Globals.longitude = lng;
                    var elevationRequest = new ElevationRequest()
                    {
                        Locations = new[] { new Location(lat, lng) },
                    };
                    if (Globals.GoogleMapsAPIKey != "")
                    {
                        elevationRequest.ApiKey = Globals.GoogleMapsAPIKey;
                    }
                    try
                    {
                        ElevationResponse elevation = GoogleMaps.Elevation.Query(elevationRequest);
                        if (elevation.Status == Status.OK)
                        {
                            foreach (Result result in elevation.Results)
                            {
                                Globals.altitude = result.Elevation;
                            }
                        }
                    }
                    catch (Exception)
                    {
                        // ignored
                    }
                    Globals.RelocateDefaultLocation = true;
                    numTravelSpeed.Value            = 0;
                    textBoxLatitude.Text            = "";
                    textBoxLongitude.Text           = "";
                    Logger.ColoredConsoleWrite(ConsoleColor.Green, "Default Location Set will navigate there after next pokestop!");
                }
            }
        }
Esempio n. 7
0
        static void Main(string[] args)
        {
            //Static class use (Directions)
            DirectionsRequest directionsRequest = new DirectionsRequest()
            {
                Origin      = "NYC, 5th and 39",
                Destination = "Philladephia, Chesnut and Wallnut",
            };

            DirectionsResponse directions = MapsAPI.GetDirections(directionsRequest);

            Console.WriteLine(directions);


            //Instance class use (Geocode)
            GeocodingRequest geocodeRequest = new GeocodingRequest()
            {
                Address = "new york city",
            };

            GeocodingEngine geocodingEngine = new GeocodingEngine();

            GeocodingResponse geocode = geocodingEngine.GetGeocode(geocodeRequest);

            Console.WriteLine(geocode);


            // Static maps API - get static map of with the path of the directions request
            StaticMapsEngine staticMapGenerator = new StaticMapsEngine();

            //Path from previos directions request
            IEnumerable <Step> steps = directions.Routes.First().Legs.First().Steps;
            // All start locations
            IList <ILocation> path = steps.Select(step => step.StartLocation).ToList <ILocation>();

            // also the end location of the last step
            path.Add(steps.Last().EndLocation);

            string url = staticMapGenerator.GenerateStaticMapURL(new StaticMapRequest(new Location(40.38742, -74.55366), 9, new ImageSize(800, 400))
            {
                Pathes = new List <Path>()
                {
                    new Path()
                    {
                        Style = new PathStyle()
                        {
                            Color = "red"
                        },
                        Locations = path
                    }
                }
            });

            Console.WriteLine("Map with path: " + url);



            //Instance class - Async! (Elevation)
            ElevationRequest elevationRequest = new ElevationRequest()
            {
                Locations = new Location[] { new Location(54, 78) },
            };

            ElevationEngine elevationEngine = new ElevationEngine();

            elevationEngine.BeginGetElevation(elevationRequest,
                                              ar =>
            {
                ElevationResponse elevation = elevationEngine.EndGetElevation(ar);
                Console.WriteLine(elevation);
            },
                                              null);

            Console.WriteLine("Finised! (But wait .. async elevation request should get response soon)");



            Console.ReadKey();
        }
Esempio n. 8
0
        private void button1_Click(object sender, EventArgs e)
        {
            //foreach (var worksheet in Workbook.Worksheets(@"D:\input\a1.csv"))
            //{
            //    foreach (var row in worksheet.Rows)
            //    {
            //        foreach (var cell in row.Cells)
            //        {
            //            cell.Amount = 4;
            //        }
            //    }
            //}
            string fname = @"D:\input\a813.csv";

            Microsoft.Office.Interop.Excel.Application xlApp       = new Microsoft.Office.Interop.Excel.Application();
            Microsoft.Office.Interop.Excel.Workbook    xlWorkbook  = xlApp.Workbooks.Open(fname);
            Microsoft.Office.Interop.Excel._Worksheet  xlWorksheet = xlWorkbook.Sheets[1];
            Microsoft.Office.Interop.Excel.Range       xlRange     = xlWorksheet.UsedRange;

            Microsoft.Office.Interop.Excel.Application xlnewApp = new Microsoft.Office.Interop.Excel.Application();

            if (xlApp == null)
            {
                MessageBox.Show("Excel is not properly installed!!");
                return;
            }
            Microsoft.Office.Interop.Excel.Workbook  xlWorkBook;
            Microsoft.Office.Interop.Excel.Worksheet xlWorkSheet;
            object misValue = System.Reflection.Missing.Value;

            xlWorkBook              = xlnewApp.Workbooks.Add(misValue);
            xlWorkSheet             = (Microsoft.Office.Interop.Excel.Worksheet)xlWorkBook.Worksheets.get_Item(1);
            xlWorkSheet.Cells[1, 1] = "X";
            xlWorkSheet.Cells[1, 2] = "Y";
            xlWorkSheet.Cells[1, 3] = "name";
            xlWorkSheet.Cells[1, 4] = "elevation";
            int rowCount = xlRange.Rows.Count;


            // i=2 bcz first row is header and rowcount-1 bcz last row not req to evaluate
            for (int i = 2; i <= rowCount - 1; i++)
            {
                // Thread.Sleep(2000);

                var longi    = xlRange.Cells[i, 1].Value2;
                var lati     = xlRange.Cells[i, 2].Value2;
                var name     = xlRange.Cells[i, 3].Value2;
                var request  = (HttpWebRequest)WebRequest.Create(string.Format("https://maps.googleapis.com/maps/api/elevation/json?locations={0},{1}&key={2}", lati, longi, "AIzaSyAqfARRG69qmS-5hykBwcyPPEMLon2S1Bo"));
                var response = (HttpWebResponse)request.GetResponse();
                var sr       = new StreamReader(response.GetResponseStream() ?? new MemoryStream()).ReadToEnd();
                var json     = JObject.Parse(sr);
                ElevationResponse elevationResponse = json.ToObject <ElevationResponse>();
                var elevation = elevationResponse.Results.First().Elevation;
                var latitude  = elevationResponse.Results.First().Location.Latitude;
                var longitude = elevationResponse.Results.First().Location.Longitude;

                //Create Excel
                //var f2Name = @"D:\output\a1.xls";
                //DataTable table = new DataTable();
                //table.Columns.Add("X", typeof(double));
                //table.Columns.Add("Y", typeof(double));
                //table.Columns.Add("name", typeof(string));
                //table.Columns.Add("elevation", typeof(double));
                //table.Rows.Add(i, latitude, longitude, name, elevation);


                //Write to excel


                xlWorkSheet.Cells[i, 1] = latitude;
                xlWorkSheet.Cells[i, 2] = longitude;
                xlWorkSheet.Cells[i, 3] = name;
                xlWorkSheet.Cells[i, 4] = elevation;

                //Here saving the file in xlsx
            }
            xlWorkBook.SaveAs("d:\\output\\a813.xlsx", Microsoft.Office.Interop.Excel.XlFileFormat.xlOpenXMLWorkbook, misValue,
                              misValue, misValue, misValue, Microsoft.Office.Interop.Excel.XlSaveAsAccessMode.xlExclusive, misValue, misValue, misValue, misValue, misValue);


            xlWorkBook.Close(true, misValue, misValue);
            xlnewApp.Quit();

            Marshal.ReleaseComObject(xlWorkSheet);
            Marshal.ReleaseComObject(xlWorkBook);
            Marshal.ReleaseComObject(xlnewApp);



            //ElevationRequest elevationRequest = new ElevationRequest()
            //{
            //    Locations = new Location[] { new Location(54, 78) },
            //};
            //try
            //{
            //    var request = new ElevationRequest { Locations = new[] { new Location(40.7141289, -73.9614074) } };
            //     result = GoogleMaps.Elevation.Query(elevationRequest);
            //    var final = result.ToString();

            //}
            //catch (Exception exception)
            //{
            //    Console.WriteLine(exception);
            //    throw;
            //}
        }