コード例 #1
0
        private string EncodeAddress(DirParameters dirpar)
        {
            var sb = new StringBuilder();


            if (!string.IsNullOrEmpty(dirpar.Origin))
            {
                sb.Append(Uri.EscapeUriString(" " + dirpar.Origin));
            }

            //if (!string.IsNullOrEmpty(dirpar.Destination))
            //    sb.Append(Uri.EscapeUriString(" " + dirpar.Destination));

            //if (!string.IsNullOrEmpty(dirpar.Mode))
            //    sb.Append(Uri.EscapeUriString(" " + dirpar.Mode));

            //if (!string.IsNullOrEmpty(dirpar.Avoid))
            //    sb.Append(Uri.EscapeUriString(" " + dirpar.Avoid));

            //if (!string.IsNullOrEmpty(dirpar.Units))
            //    sb.Append(Uri.EscapeUriString(" " + dirpar.Units));


            return(sb.ToString());
        }
コード例 #2
0
        public DirResult DirInfo(DirParameters dirpar)
        {
            if (string.IsNullOrEmpty(Key))
            {
                throw new MissingFieldException("Your Google API Key is missing");
            }

            using (var client = new WebClient())
            {
                var    sO            = new StringBuilder();
                var    sD            = new StringBuilder();
                var    sM            = new StringBuilder();
                var    sA            = new StringBuilder();
                var    sU            = new StringBuilder();
                string formatAddress = string.Format(GGeoCodeJsonServiceUrl, sO.Append(Uri.EscapeUriString(dirpar.Origin)), sD.Append(Uri.EscapeUriString(dirpar.Destination)), sM.Append(Uri.EscapeUriString(dirpar.Mode)), sA.Append(Uri.EscapeUriString(dirpar.Avoid)), sU.Append(Uri.EscapeUriString(dirpar.Units)), Key);
                var    result        = client.DownloadString(formatAddress);
                var    O             = JsonConvert.DeserializeObject <DirResult>(result);
                SetGeoResultFlag(O.status);
                return(O);
            }
        }