Esempio n. 1
0
        protected override void ConfigureUnderlyingWebClient(WebClient wc, MapsBaseRequest baseRequest)
        {
            ElevationRequest request = (ElevationRequest)baseRequest;

            NameValueCollection queryString = wc.QueryString;

            if (request.Locations != null)
            {
                var locationsStrings = request.Locations.Select(location => string.Format("{0},{1}", location.Latitude, location.Longitude));

                string allLocations = string.Join("|", locationsStrings);
                queryString.Add("locations", allLocations);
            }
            else if (request.Path != null)
            {
                var points = request.Path.Select(path => string.Format("{0},{1}", path.Latitude, path.Longitude));
                queryString.Add("path", string.Join("|", points));
            }
            else
            {
                throw new ArgumentException("Locations or Path must be specified");
            }

            queryString.Add("sensor", request.Sensor.ToString().ToLower());
        }
Esempio n. 2
0
        override protected void ConfigureUnderlyingWebClient(WebClient wc, MapsBaseRequest baseRequest)
        {
            GeocodingRequest request = (GeocodingRequest)baseRequest;

            NameValueCollection queryString = wc.QueryString;

            if (request.Location == null &&
                string.IsNullOrWhiteSpace(request.Address))
            {
                throw new ArgumentException("Location OR Address is required");
            }


            if (request.Location != null)
            {
                queryString.Add("latlng",
                                string.Format("{0},{1}", request.Location.Latitude, request.Location.Longitude));
            }
            if (!string.IsNullOrWhiteSpace(request.Address))
            {
                queryString.Add("address", request.Address);
            }

            if (request.Bounds != null)
            {
                //Convert each bound to string
                var boundsStrings = request.Bounds.Select(
                    bound =>
                    string.Format("{0},{1}", bound.Latitude, bound.Longitude));

                queryString.Add("bounds", string.Join("|", boundsStrings));
            }

            if (!string.IsNullOrWhiteSpace(request.Region))
            {
                queryString.Add("region", request.Region);
            }

            if (!string.IsNullOrWhiteSpace(request.Language))
            {
                queryString.Add("language", request.Language);
            }

            queryString.Add("sensor", request.Sensor.ToString().ToLower());
        }
Esempio n. 3
0
        protected override void ConfigureUnderlyingWebClient(WebClient wc, MapsBaseRequest baseRequest)
        {
            DirectionsRequest request = (DirectionsRequest)baseRequest;

            NameValueCollection queryString = wc.QueryString;

            if (!string.IsNullOrWhiteSpace(request.Origin))
            {
                queryString.Add("origin", request.Origin);
            }
            else
            {
                throw new ArgumentException("Must specify Origin");
            }

            if (!string.IsNullOrWhiteSpace(request.Destination))
            {
                queryString.Add("destination", request.Destination);
            }
            else
            {
                throw new ArgumentException("Must specify Destination");
            }

            if (request.Alternatives)
            {
                queryString.Add("alternatives", "true");
            }

            switch (request.Avoid)
            {
            case AvoidWay.Nothing:
                break;

            case AvoidWay.Tolls:
                queryString.Add("avoid", "tolls");
                break;

            case AvoidWay.Highways:
                queryString.Add("avoid", "highways");
                break;

            default:
                throw new ArgumentException("Unknown value for 'AvoidWay' enum");
            }

            if (!string.IsNullOrWhiteSpace(request.Language))
            {
                queryString.Add("language", request.Language);
            }

            queryString.Add("sensor", request.Sensor.ToString().ToLower());

            if (request.Waypoints != null)
            {
                string wayPoints = string.Join("|", request.Waypoints);
                queryString.Add("waypoints", wayPoints);
            }

            switch (request.TravelMode)
            {
            case TravelMode.Driving:
                queryString.Add("mode", "driving");
                break;

            case TravelMode.Bicycling:
                queryString.Add("mode", "bicycling");
                break;

            case TravelMode.Walking:
                queryString.Add("mode", "walking");
                break;

            default:
                throw new ArgumentException("Unknown value for 'TravelMode' enum");
            }
        }
Esempio n. 4
0
        protected override void ConfigureUnderlyingWebClient(WebClient wc, MapsBaseRequest baseRequest)
        {
            PlacesRequest request = (PlacesRequest)baseRequest;

            NameValueCollection queryString = wc.QueryString;

            if (request.Location != null)
            {
                queryString.Add("location", request.Location.LocationString);
            }
            else
            {
                throw new ArgumentException("Location must be povided", "Location");
            }

            if (request.Radius.HasValue)
            {
                double radius = request.Radius.Value;

                if (radius > 50000 || radius < 1)
                {
                    throw new ArgumentException("Radius must be in range (1, 50000)", "Radius");
                }

                queryString.Add("radius", request.Radius.Value.ToString(CultureInfo.InvariantCulture));
            }
            else
            {
                if (request.RankBy != RankBy.Distance)
                {
                    throw new ArgumentException("Radius must be specified unless RankBy is 'Distance'", "Radius");
                }
            }

            if (!string.IsNullOrWhiteSpace(request.Keyword))
            {
                queryString.Add("keyword", request.Keyword);
            }

            if (!string.IsNullOrWhiteSpace(request.Language))
            {
                queryString.Add("language", request.Language);
            }


            if (!string.IsNullOrWhiteSpace(request.Types))
            {
                queryString.Add("types", request.Types);
            }

            if (!string.IsNullOrWhiteSpace(request.Name))
            {
                queryString.Add("name", request.Name);
            }

            switch (request.RankBy)
            {
            case RankBy.Prominence:
                break;

            case RankBy.Distance:
                queryString.Add("rankby", "distance");
                break;

            default:
                throw new ArgumentOutOfRangeException();
            }


            queryString.Add("sensor", request.Sensor.ToString().ToLower());

            if (!string.IsNullOrWhiteSpace(request.ApiKey))
            {
                queryString.Add("key", request.ApiKey);
            }
            else
            {
                throw new ArgumentException("ApiKey must be povided", "ApiKey");
            }
        }
Esempio n. 5
0
 protected abstract void ConfigureUnderlyingWebClient(WebClient wc, MapsBaseRequest request);
Esempio n. 6
0
        private Uri GetUri(MapsBaseRequest request)
        {
            string scheme = request.IsSSL ? "https://" : "http://";

            return(new Uri(scheme + BaseUrl + "json"));
        }