public void GetElevationForTwoLocations()
        {
            // expectations
            var expectedStatus      = ServiceResponseStatus.Ok;
            var expectedResultCount = 2;

            var expectedElevation1 = 1608.6m;
            var expectedLocation1  = new LatLng(39.739153, -104.984703);
            var expectedElevation2 = -50.789m;
            var expectedLocation2  = new LatLng(36.4555560, -116.8666670);

            // test
            var request = new ElevationRequest();

            request.AddLocations(expectedLocation1, expectedLocation2);
            request.Sensor = false;
            var response = new ElevationService().GetResponse(request);

            // asserts
            Assert.AreEqual(expectedStatus, response.Status);

            Assert.AreEqual(expectedResultCount, response.Results.Length);

            Assert.That(expectedElevation1, Is.EqualTo(response.Results[0].Elevation).Within(0.1));
            Assert.That(expectedLocation1, Is.EqualTo(response.Results[0].Location));

            Assert.That(expectedElevation2, Is.EqualTo(response.Results[1].Elevation).Within(0.1));
            Assert.That(expectedLocation2, Is.EqualTo(response.Results[1].Location));
        }
Esempio n. 2
0
        public double GetElevation(double _latitude, double _longitude, double _altitude = 0)
        {
            ElevationRequest elevationRequest = new ElevationRequest();

            elevationRequest.AddLocations(new LatLng(_latitude, _longitude));
            elevationRequest.Sensor = false;

            try
            {
                ElevationResponse elevation = new ElevationService().GetResponse(elevationRequest);
                if (elevation.Status == ServiceResponseStatus.Ok)
                {
                    return((double)elevation.Results[0].Elevation);
                }
                else
                {
                    return(_altitude);
                }
            }
            catch (Exception ex)
            {
                Logger.ColoredConsoleWrite(ConsoleColor.Red, "Error: LocationHelper.cs - GetElevation");
                Logger.ColoredConsoleWrite(ConsoleColor.Red, ex.Message);
                return(_altitude);
            }
        }
        public void GetElevationForOneLocation()
        {
            // expectations
            var expectedStatus      = ServiceResponseStatus.Ok;
            var expectedResultCount = 1;
            var expectedElevation   = 1608.6m;
            var expectedLocation    = new LatLng(39.739153, -104.984703);

            // test
            var request = new ElevationRequest();

            request.AddLocations(expectedLocation);
            request.Sensor = false;
            var response = new ElevationService().GetResponse(request);

            // asserts
            Assert.AreEqual(expectedStatus, response.Status);
            Assert.AreEqual(expectedResultCount, response.Results.Length);

            Assert.That(expectedElevation, Is.EqualTo(response.Results[0].Elevation).Within(0.1));

            Assert.That(expectedLocation, Is.EqualTo(response.Results[0].Location));
        }