/// <summary>
        /// Create URI for quering
        /// </summary>
        /// <returns></returns>
        public override Uri ToUri()
        {
            var qsb = new Internal.QueryStringBuilder()
                      .Append("origins", WaypointsToUri(_waypointsOrigin))
                      .Append("destinations", WaypointsToUri(_waypointsDestination))
                      .Append("mode", Mode.ToString())
                      .Append("language", Language)
                      .Append("units", Units.ToString())
                      .Append("avoid", AvoidHelper.MakeAvoidString(Avoid))
                      .Append("departure_time", DepartureTime.ToString());

            if (DepartureTime == null)
            {
                qsb.Append("arrival_time", ArrivalTime.ToString());
            }

            if (DepartureTime != null && Mode.Equals(TravelMode.driving))
            {
                qsb.Append("traffic_model ", TrafficModel.ToString());
            }

            if (Mode.Equals(TravelMode.transit))
            {
                qsb.Append("transit_mode", TransitMode.ToString());
                qsb.Append("transit_routing_preference ", TransitRoutingPreference.ToString());
            }

            var url = "json?" + qsb.ToString();

            return(new Uri(url, UriKind.Relative));
        }
        public string ToURIString()
        {
            string uri = "origins=";

            foreach (var orig in Origins)
            {
                if (orig != Origins.First())
                {
                    uri += "|";
                }
                uri += orig.ToLocationString();
            }

            uri += "&destinations=";
            foreach (var orig in Destinations)
            {
                if (orig != Destinations.First())
                {
                    uri += "|";
                }
                uri += orig.ToLocationString();
            }

            if (string.IsNullOrEmpty(Language))
            {
                uri += "&language=" + Language;
            }

            if (Mode != null)
            {
                uri += "&mode=" + Mode.ToString();
            }

            if (Avoid != null)
            {
                uri += "&avoid=" + Avoid.ToString();
            }

            if (string.IsNullOrWhiteSpace(Region))
            {
                uri += "&region=" + Region;
            }

            if (TrafficModel != null)
            {
                uri += "&trafficmodel=" + TrafficModel.ToString();
            }

            if (TransitMode != null)
            {
                uri += "&transit=" + TransitMode.ToString();
            }

            if (preference != null)
            {
                uri += "&transit_routing_preference=" + preference.ToString();
            }

            return(uri);
        }
Ejemplo n.º 3
0
 public string GetTransitScene(TransitMode mode)
 {
     if (mode == TransitMode.RETRY)
     {
         return(cleardata.stageName);
     }
     else if (mode == TransitMode.NEXT)
     {
         return(SaveDataManager.Instance.GetNextSaveData(cleardata.stageName).stageName);
     }
     return(null);
 }
        public override string ToString()
        {
            Dictionary <string, string> parameters = new Dictionary <string, string>();

            //adding required parrameters
            if (Origin != null)
            {
                parameters.Add("origin", Origin.ToString());
            }

            if (Destination != null)
            {
                parameters.Add("destination", value: Destination.ToString());
            }

            if (!string.IsNullOrEmpty(Key))
            {
                parameters.Add("key", Key);
            }


            //adding optional parametres
            if (TravelMode != null)
            {
                parameters.Add("mode", TravelMode.Value.ToString());
            }

            if (WayPoints != null && WayPoints.Count > 0)
            {
                parameters.Add("waypoints", string.Join("|", WayPoints.Distinct().Select(d => d.ToString())));
            }

            if (Alternatives)
            {
                parameters.Add("alternatives", Alternatives.ToString());
            }

            if (Avoid != null)
            {
                parameters.Add("avoid", string.Join("|", Avoid.Distinct().Select(d => d.ToString())));
            }

            if (!string.IsNullOrEmpty(Language))
            {
                parameters.Add("language", Language);
            }

            if (Units is UnitSystem.imperial)
            {
                parameters.Add("units", Units.ToString());
            }

            if (!string.IsNullOrEmpty(Region))
            {
                parameters.Add("region", Region);
            }

            if (!string.IsNullOrEmpty(ArrivalTime))
            {
                parameters.Add("arrival_time",
                               _ArrivalTime - new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc) != null
                        ? Math.Floor((_ArrivalTime.Value.ToUniversalTime() - new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc)).TotalSeconds).ToString(CultureInfo.InvariantCulture)
                        : null);
            }

            if (!string.IsNullOrEmpty(DepartureTime))
            {
                parameters.Add("departure_time",
                               _DepartureTime != null
                        ?Math.Floor((_DepartureTime.Value.ToUniversalTime() - new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc))
                                    .TotalSeconds).ToString(CultureInfo.InvariantCulture)
                        : null);
            }

            if (TrafficModel != null)
            {
                parameters.Add("traffic_model", TrafficModel.ToString());
            }

            if (TransitMode != null)
            {
                parameters.Add("transit_mode", string.Join("|", TransitMode.Distinct().Select(d => d.ToString())));
            }

            if (TransitRoutingPreferences != null)
            {
                parameters.Add("transit_routing_preference", TransitRoutingPreferences.ToString());
            }

            return(string.Join("&", parameters.Select(d => d.Key + "=" + d.Value)));
        }
        public override string ToString()
        {
            Dictionary <string, string> parameters = new Dictionary <string, string>();

            //adding required parrameters
            if (Origins != null)
            {
                parameters.Add("origins", string.Join("|", Origins.Select(d => d.ToString())));
            }

            if (Destinations != null)
            {
                parameters.Add("destinations", string.Join("|", Destinations.Select(d => d.ToString())));
            }

            if (!string.IsNullOrEmpty(Key))
            {
                parameters.Add("key", Key);
            }


            //adding optional parametres
            if (TravelMode != null)
            {
                parameters.Add("mode", TravelMode.Value.ToString());
            }



            if (Avoid != null)
            {
                parameters.Add("avoid", string.Join("|", Avoid.Distinct().Select(d => d.ToString())));
            }

            if (string.IsNullOrEmpty(Language))
            {
                parameters.Add("language", Language);
            }

            if (Units is UnitSystem.imperial)
            {
                parameters.Add("units", Units.ToString());
            }

            if (string.IsNullOrEmpty(Region))
            {
                parameters.Add("region", Region);
            }

            if (ArrivalTime != null)
            {
                parameters.Add("arrival_time",
                               ArrivalTime - new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc) != null
                        ? (ArrivalTime.Value - new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc)).Seconds.ToString()
                        : null);
            }

            if (DepartureTime != null)
            {
                parameters.Add("departure_time",
                               DepartureTime - new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc) != null
                        ? (DepartureTime.Value - new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc)).Seconds.ToString()
                        : null);
            }

            if (TrafficModel != null)
            {
                parameters.Add("traffic_model", TrafficModel.ToString());
            }

            if (TransitMode != null)
            {
                parameters.Add("transit_mode", string.Join("|", TransitMode.Distinct().Select(d => d.ToString())));
            }

            if (TransitRoutingPreference != null)
            {
                parameters.Add("transit_routing_preference", TransitRoutingPreference.ToString());
            }

            return(string.Join("&", parameters.Select(d => d.Key + "=" + d.Value)));
        }