示例#1
0
        /// <summary>
        /// Gets a URL for requesting traffic data for a GET request.
        /// </summary>
        /// <returns>Traffic request URL for GET request.</returns>
        public override string GetRequestUrl()
        {
            //URL Schema:
            //https://dev.virtualearth.net/REST/v1/Traffic/Incidents/mapArea/includeLocationCodes?severity=severity1,severity2,severityn&type=type1,type2,typen&key=BingMapsKey

            //Examples:
            //https://dev.virtualearth.net/REST/v1/Traffic/Incidents/37,-105,45,-94?key=YourBingMapsKey
            //https://dev.virtualearth.net/REST/V1/Traffic/Incidents/37,-105,45,-94/true?t=9,2&s=2,3&o=xml&key=BingMapsKey

            if (MapArea == null)
            {
                throw new Exception("MapArea not specified.");
            }

            string url = string.Format(CultureInfo.InvariantCulture, "https://dev.virtualearth.net/REST/V1/Traffic/Incidents/{0:0.#####},{1:0.#####},{2:0.#####},{3:0.#####}{4}",
                                       MapArea.SouthLatitude,
                                       MapArea.WestLongitude,
                                       MapArea.NorthLatitude,
                                       MapArea.EastLongitude,
                                       (IncludeLocationCodes)? "/true?" : "?");

            if (Severity != null && Severity.Count > 0)
            {
                url += "&severity=" + string.Join(",", Severity.Cast <int>().ToArray());
            }

            if (TrafficType != null && TrafficType.Count > 0)
            {
                url += "&type=" + string.Join(",", TrafficType.Cast <int>().ToArray());
            }

            return(url + GetBaseRequestUrl());
        }