Example #1
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;
            }
        }
Example #2
0
 /// <summary>
 /// Initializes a new instance of the GeocodeRequest class.
 /// </summary>
 /// <param name="address">The address to make the geocode request for.</param>
 /// <param name="apiKey">The API key to use when making the request.</param>
 public GeocodeRequest(GeocodeRequestAddress address, string apiKey)
 {
     this.Address = address;
     this.ApiKey = apiKey;
     this.RequestUri = CreateRequestUri(address, apiKey);
 }
Example #3
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;
        }
Example #4
0
 /// <summary>
 /// Initializes a new instance of the GeocodeRequest class.
 /// </summary>
 /// <param name="address">The address to make the geocode request for.</param>
 public GeocodeRequest(GeocodeRequestAddress address)
     : this(address, TastySettings.Section.Geocode.ApiKey)
 {
 }
Example #5
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>
 /// <returns>The result of the request.</returns>
 public static GeocodeCallResult Make(GeocodeRequestAddress address, string apiKey)
 {
     return Make(address, apiKey, 0);
 }
Example #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="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, int minimumAccuracy)
 {
     return Make(address, TastySettings.Section.Geocode.ApiKey, minimumAccuracy);
 }
Example #7
0
 /// <summary>
 /// Makes a geocode request with the given address.
 /// </summary>
 /// <param name="address">The address to make the request with.</param>
 /// <returns>The result of the request.</returns>
 public static GeocodeCallResult Make(GeocodeRequestAddress address)
 {
     return Make(address, TastySettings.Section.Geocode.ApiKey);
 }
Example #8
0
        /// <summary>
        /// Creates a request URI to use in a geocode request for the given address.
        /// Restricts the geocode request to the United States.
        /// </summary>
        /// <param name="address">The address to create a request URI for.</param>
        /// <param name="apiKey">The API key to use when making the request.</param>
        /// <returns>A geocode service request URI.</returns>
        public static Uri CreateRequestUri(GeocodeRequestAddress address, string apiKey)
        {
            QueryString query = new QueryString();
            query.Add("q", address.ToString());
            query.Add("key", apiKey);
            query.Add("sensor", "false");
            query.Add("output", "json");
            query.Add("oe", "utf8");
            query.Add("gl", ".us");

            return CreateRequestUri(query);
        }
Example #9
0
 /// <summary>
 /// Creates a request URI to use in a geocode request for the given address.
 /// Restricts the geocode request to the United States.
 /// </summary>
 /// <param name="address">The address to create a request URI for.</param>
 /// <returns>A geocode service request URI.</returns>
 public static Uri CreateRequestUri(GeocodeRequestAddress address)
 {
     return CreateRequestUri(address, TastySettings.Section.Geocode.ApiKey);
 }