Esempio n. 1
0
        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);
            }
        }
Esempio n. 2
0
        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);
            }
        }
Esempio n. 3
0
        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);
            }
        }
Esempio n. 4
0
        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);
            }
        }
Esempio n. 5
0
 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);
     }
 }
Esempio n. 6
0
        /// <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;
        }