Exemple #1
0
        private void btnAnalysis_Click(object sender, EventArgs e)
        {
            Coordinates = new List <CoordinateVM>();
            var index = 1;

            using (MyHttpClient Client = new MyHttpClient())
            {
                var Result = Client.GetStringAsync(tbCoordinates.Text).Result;

                var coordinatesString = JArray.Parse(Result)[0]["Geometry"].ToString().Replace("LINESTRING", "").Replace("(", "").Replace(")", "");
                foreach (var i in coordinatesString.Split(tbSplitCoordinates.Text[0]))
                {
                    var c = i.Split(tbSplitLonLat.Text[0])
                            .Where(a => !string.IsNullOrEmpty(a.Trim()))
                            .Select(a => double.Parse(a.Trim()));
                    Coordinates.Add(new CoordinateVM()
                    {
                        Index     = index++,
                        Latitude  = c.First() < 120 ? c.First() : c.Last(),
                        Longitude = c.First() > 120 ? c.First() : c.Last(),
                    });
                }
            }

            colJson.Visible          = false;
            gvCoordinates.DataSource = Coordinates;
            btnAnalysis.Enabled      = true;
            lbxNoMatchs.Visible      = false;
            lbNoMatch.Visible        = false;
            btnMap.Enabled           = false;
        }
Exemple #2
0
        private void cbCity_SelectedIndexChanged(object sender, EventArgs e)
        {
            var    selectedCity = (cbCityVM)cbCity.SelectedItem;
            string url          = "http://ptx.transportdata.tw/MOTC/v2/Bus/Shape/City/" + selectedCity.Value + "?$select=RouteID%2CRouteName&$format=JSON";

            using (MyHttpClient Client = new MyHttpClient())
            {
                var json = Client.GetStringAsync(url).Result;
                citys = JArray.Parse(json).ToObject <CityVM[]>();
                gvResult.DataSource = citys;
            }
        }