Пример #1
0
        /// <summary>
        /// 透過座標取得腳踏車資訊
        /// </summary>
        /// <param name="talkToken">要發送給誰</param>
        /// <param name="lat">緯度</param>
        /// <param name="lon">經度</param>
        /// <returns></returns>
        public string returnBikeData(string talkToken, string lat, string lon)
        {
            PTXApi getBusLocation = new PTXApi();

            string APIUrl = "http://ptx.transportdata.tw/MOTC/v2/Bike/Station/taipei?$format=JSON";
            List <YoubikeModel> getData = JsonConvert.DeserializeObject <List <Models.YoubikeModel> >(CallAPIByHMAC(APIUrl));

            foreach (var data in getData)
            {
                var distance = Math.Abs(Geocoding.DistanceOfTwoPoints(Convert.ToDouble(data.StationPosition.PositionLat), Convert.ToDouble(data.StationPosition.PositionLon), Convert.ToDouble(lat), Convert.ToDouble(lon)));
                data.Distance = distance;
            }

            var finalLocation = getData.OrderBy(x => x.Distance).Take(3);

            if (finalLocation.Count() > 0)
            {
                foreach (var item in finalLocation)
                {
                    string stationStatus = BikeStationStatus(item.StationUID, "taipei");
                    SendRequest.SendLocation(talkToken, item.StationPosition.PositionLat, item.StationPosition.PositionLon, item.StationName.Zh_tw, stationStatus);
                }
                return("Youbike站台資訊如上");
            }
            else
            {
                return("");
            }
        }
Пример #2
0
        public static async void MakeAnalysisRequest(byte[] image, string id)
        {
            const string subscriptionKey = "0c4249a2c107480fb7af63c540d73768";
            const string uriBase         = "https://westcentralus.api.cognitive.microsoft.com/vision/v1.0/analyze";

            HttpClient http = new HttpClient();

            // Request headers.
            http.DefaultRequestHeaders.Add("Ocp-Apim-Subscription-Key", subscriptionKey);

            // Request parameters. A third optional parameter is "details".
            string requestParameters = "visualFeatures=Categories,Description,Color&language=en";

            // Assemble the URI for the REST API Call.
            string uri = uriBase + "?" + requestParameters;

            HttpResponseMessage response;

            try
            {
                using (ByteArrayContent content = new ByteArrayContent(image))
                {
                    content.Headers.ContentType = new MediaTypeHeaderValue("application/octet-stream");

                    SendRequest.SendLine("分析中 ... 請稍候", id);

                    response = await http.PostAsync(uri, content);


                    string contentString = await response.Content.ReadAsStringAsync();

                    Models.VRModel SerlizeData = JsonConvert.DeserializeObject <Models.VRModel>(contentString);

                    SendRequest.SendLine("圖片分析結果 ... 可能是:\n" + SerlizeData.description.captions.FirstOrDefault().text +
                                         "\n信心指數: " + SerlizeData.description.captions.FirstOrDefault().confidence, id);
                }
            }
            catch (Exception ex)
            {
                throw;
            }
        }