Beispiel #1
0
        public JsonAddress GetAddressDetails(Address address)
        {
            var addressDetails = address.Street + " " + address.BuildingNumber + " " + address.City;
            var client         = new RestSharp.RestClient("https://eu1.locationiq.com/");
            var request        = new RestSharp.RestRequest("v1/search.php", RestSharp.Method.GET);

            request.AddParameter("key", "c24325218ea6eb");
            request.AddParameter("accept-language", "he");
            request.AddParameter("q", addressDetails);
            request.AddParameter("format", "json");
            var res = client.Execute(request);

            if (res.StatusCode == System.Net.HttpStatusCode.OK)
            {
                var content    = JsonConvert.DeserializeObject <object>(res.Content);
                var parsedJson = JArray.Parse(content.ToString());
                var Jaddress   = new JsonAddress
                {
                    Latitude    = parsedJson[0]["lat"].ToString(),
                    Longitude   = parsedJson[0]["lon"].ToString(),
                    DisplayName = parsedJson[0]["display_name"].ToString()
                };
                return(Jaddress);
            }
            return(null);
        }
        /// <summary>
        /// Verifies the suggest address. This POST operation obtains suggested addresses in cases where the
        /// Address Validation API call has returned an error.
        /// 1. The suggested addresses are **not** validated addresses. You must reissue
        /// the API call.
        ///
        /// 2. Some suggestions might not be valid delivery points. This is especially
        /// true for range suggestions. For example, if the suggested valid range for a
        /// street is 1-100, the Suggest Addresses API call will consider all numbers
        /// the range to be valid, even if the only valid delivery points are
        /// numbers 12, 24, and 36.
        ///
        /// 3. The operation provides several types of suggestions:
        /// - Range suggestions:
        /// - Primary number range (e.g., street number, PO Box number)
        /// - Secondary number range(e.g., suite number, apartment number
        /// - Street Name
        /// - City Name
        /// - Company Name
        /// - Puerto Rican Urbanization
        ///
        /// 4. The suggested addresses are **not** sorted by best match.
        ///
        /// 5. The API returns a maximum of 20 suggestions.
        ///
        /// 6. Some addresses might return no suggestions. If there are no
        /// suggestions, the ``suggestions`` object is not returned.
        /// </summary>
        /// <returns>The suggest address.</returns>
        /// <param name="request">Request.</param>
        /// <param name="session">Session.</param>
        /// <typeparam name="T">The 1st type parameter.</typeparam>
        public async static Task <ShippingApiResponse <VerifySuggestResponse> > VerifySuggestAddress <T>(T request, ISession session = null) where T : IAddress, new()
        {
            var verifyRequest = new JsonAddress <T>(request)
            {
                Suggest = true
            };

            return(await WebMethod.Post <VerifySuggestResponse, JsonAddress <T> >("/shippingservices/v1/addresses/verify-suggest", verifyRequest, session));
        }