コード例 #1
0
ファイル: GeocodeTests.cs プロジェクト: ChadBurggraf/tasty
        public void GeocodeAdministrativeAreaForHome()
        {
            if (!String.IsNullOrEmpty(TastySettings.Section.Geocode.ApiKey))
            {
                GeocodeRequest request = new GeocodeRequest(HomeAddress);
                GeocodeResponse response = request.GetResponse();

                GeocodePlacemark mark = response.Placemark.First();

                Assert.AreEqual("AZ", mark.AddressDetails.Country.AdministrativeArea.AdministrativeAreaName);
                Assert.AreEqual("Scottsdale", mark.AddressDetails.Country.AdministrativeArea.Locality.LocalityName);
                Assert.AreEqual("6840 E 2nd St #22", mark.AddressDetails.Country.AdministrativeArea.Locality.Thoroughfare.ThoroughfareName);
                Assert.AreEqual("85251", mark.AddressDetails.Country.AdministrativeArea.Locality.PostalCode.PostalCodeNumber);
            }
        }
コード例 #2
0
        /// <summary>
        /// Initializes a new instance of the GeocodeException class.
        /// </summary>
        /// <param name="request">The request that caused the exception to be thrown.</param>
        /// <param name="response">The response that caused the exception to be thrown.</param>
        public GeocodeException(GeocodeRequest request, GeocodeResponse response)
            : this()
        {
            if (request != null)
            {
                this.address = request.Address;
                this.requestUri = request.RequestUri;
            }

            if (response != null)
            {
                this.responseName = response.Name;
                this.responseStatusCode = response.Status.Code;
            }
        }
コード例 #3
0
ファイル: GeocodeTests.cs プロジェクト: ChadBurggraf/tasty
        public void GeocodeAdministrativeAreaForCity()
        {
            if (!String.IsNullOrEmpty(TastySettings.Section.Geocode.ApiKey))
            {
                GeocodeRequest request = new GeocodeRequest(new GeocodeRequestAddress()
                {
                    City = "Scottsdale",
                    State = "AZ"
                });

                GeocodeResponse response = request.GetResponse();
                GeocodePlacemark mark = response.Placemark.First();

                Assert.AreEqual("AZ", mark.AddressDetails.Country.AdministrativeArea.AdministrativeAreaName);
                Assert.AreEqual("Scottsdale", mark.AddressDetails.Country.AdministrativeArea.SubAdministrativeArea.Locality.LocalityName);
            }
        }
コード例 #4
0
ファイル: GeocodeTests.cs プロジェクト: ChadBurggraf/tasty
        public void GeocodeCity()
        {
            if (!String.IsNullOrEmpty(TastySettings.Section.Geocode.ApiKey))
            {
                GeocodeRequest request = new GeocodeRequest(new GeocodeRequestAddress()
                {
                    City = "Scottsdale",
                    State = "AZ"
                });

                GeocodeResponse response = request.GetResponse();
                Assert.AreEqual<GeocodeResposeStatusCode>(GeocodeResposeStatusCode.Success, response.Status.Code);

                var mark = (from p in response.Placemark
                            orderby p.AddressDetails.Accuracy descending
                            select p).First();

                Assert.IsTrue(mark.AddressDetails.Accuracy >= 4);
            }
        }
コード例 #5
0
ファイル: GeocodeTests.cs プロジェクト: ChadBurggraf/tasty
        public void GeocodetLatLonForHome()
        {
            if (!String.IsNullOrEmpty(TastySettings.Section.Geocode.ApiKey))
            {
                GeocodeRequest request = new GeocodeRequest(HomeAddress);
                GeocodeResponse response = request.GetResponse();

                decimal latDiff = Math.Abs(HomeCoordinates.Latitude.Value - response.Placemark[0].Point.Latitude.Value);
                decimal lonDIff = Math.Abs(HomeCoordinates.Longitude.Value - response.Placemark[0].Point.Longitude.Value);

                Assert.IsTrue(latDiff < 0.001m);
                Assert.IsTrue(lonDIff < 0.001m);
            }
        }
コード例 #6
0
ファイル: GeocodeTests.cs プロジェクト: ChadBurggraf/tasty
 public void GeocodeMakeRequest()
 {
     if (!String.IsNullOrEmpty(TastySettings.Section.Geocode.ApiKey))
     {
         GeocodeRequest request = new GeocodeRequest(HomeAddress);
         GeocodeResponse response = request.GetResponse();
         Assert.AreEqual<GeocodeResposeStatusCode>(GeocodeResposeStatusCode.Success, response.Status.Code);
     }
 }
コード例 #7
0
ファイル: GeocodeRequest.cs プロジェクト: ChadBurggraf/tasty
        /// <summary>
        /// Makes a geocode request with the given address.
        /// </summary>
        /// <param name="address">The address to make the request with.</param>
        /// <param name="apiKey">The API key to use when making the request.</param>
        /// <param name="minimumAccuracy">The minimum accuracy requred for a successful response, or 0 if not applicable.</param>
        /// <returns>The result of the request.</returns>
        public static GeocodeCallResult Make(GeocodeRequestAddress address, string apiKey, int minimumAccuracy)
        {
            GeocodeCallResult result = new GeocodeCallResult();

            try
            {
                GeocodeRequest request = new GeocodeRequest(address, apiKey);
                GeocodeResponse response = request.GetResponse();

                if (response.Status.Code == GeocodeResposeStatusCode.Success)
                {
                    var mark = (from p in response.Placemark
                                orderby p.AddressDetails.Accuracy descending
                                select p).First();

                    result.Placemark = mark;

                    if (minimumAccuracy == 0 || mark.AddressDetails.Accuracy >= minimumAccuracy)
                    {
                        result.Status = GeocodeCallStatus.Successful;
                    }
                    else
                    {
                        result.Status = GeocodeCallStatus.NotEnoughAccuracy;
                    }
                }
                else
                {
                    result.Status = GeocodeCallStatus.Unsuccessful;
                }
            }
            catch (GeocodeException)
            {
                result.Status = GeocodeCallStatus.Unsuccessful;
            }

            return result;
        }