예제 #1
0
        public async void getPost() {
            post.Clear();
           // Map.Children.Clear();

            HttpClient client = new HttpClient();
            var postData = new List<KeyValuePair<string, string>>();
            postData.Add(new KeyValuePair<string, string>("latitude", lati.ToString()));
            postData.Add(new KeyValuePair<string, string>("longtitude", longti.ToString()));
            postData.Add(new KeyValuePair<string, string>("uid", user.id.ToString()));
            HttpContent c = new FormUrlEncodedContent(postData);
            var response = await client.PostAsync("http://localhost/view.php", c);
           
            var str = await response.Content.ReadAsStringAsync();
           
            string s = str.ToString();
    
            Debug.WriteLine(s);

            if (s.Equals("Not Found"))
            {
                Debug.WriteLine("in if not found");
                Pushpin pin = new Pushpin();

                pin.Text = "error";
                MapLayer.SetPosition(pin, new Location(14.27570, 101.2890));
                //pushpin.Tapped += new TappedEventHandler(pushpinTapped);
                Map.Children.Add(pin);
            }
            else {
                var o = JArray.Parse(s);

                Debug.WriteLine("in else");
                int i = 0;
                while (i < o.Count)
                {
                    Post tmp = new Post();
                 
                    tmp.p_id = (int)o[i]["p_id"];
                    
                    tmp.latitude = (double)o[i]["latitude"];
                   
                    tmp.longtitude = (double)o[i]["longtitude"];
                   
                    tmp.dateTime = (string)o[i]["date_time"];
               
                    tmp.id = (int)o[i]["id"];
                
                    tmp.description = (string)o[i]["description"];
       
                    tmp.status = (int)o[i]["status"];
                 
                    tmp.countSolve = (int)o[i]["count_solved"];
                    
                    tmp.countSeen = (int)o[i]["count_seen"];
                   
                    tmp.countSpam = (int)o[i]["count_spam"];
                  
                    tmp.nameTag.Add((string)o[i]["nametag"]);
                    i++;
                    if (i >= o.Count)
                    {
                        post.Add(tmp);
                    }
                    else {
                        if (tmp.id != (int)o[i]["p_id"])
                        {
                            post.Add(tmp);
                            continue;
                        }
                        else
                        {
                            while (tmp.id == (int)o[i]["p_id"])
                            {
                                tmp.nameTag.Add((string)o[i]["nametag"]);
                                i++;
                            }
                            post.Add(tmp);
                        }
                    }  
                }
                foreach (var item in post)
                {
                    Debug.WriteLine(item.p_id + " " + item.nameTag);
                }
                /*
                for (int j = 0; j < post.Count; j++)
                {
                    Pushpin pushpin = new Pushpin();
                    pushpin.Text = "1";
                    MapLayer.SetPosition(pushpin, new Location(post.ElementAt(j).latitude, post.ElementAt(j).longtitude));
                    pushpin.Tapped += new TappedEventHandler(pushpinTapped);
                    Map.Children.Add(pushpin);
                    Debug.WriteLine("Sleepy");
                }*/
            }
        }
예제 #2
0
        public async void getPost() {
            
            string latitude = pos.Coordinate.Latitude.ToString();
            string longtitude = pos.Coordinate.Longitude.ToString();

            HttpClient client = new HttpClient();
            var postData = new List<KeyValuePair<string, string>>();
            postData.Add(new KeyValuePair<string, string>("latitude", latitude));
            postData.Add(new KeyValuePair<string, string>("longtitude", longtitude));
            postData.Add(new KeyValuePair<string, string>("uid", nowLogin.id.ToString()));

            HttpContent c = new FormUrlEncodedContent(postData);
            var response = await client.PostAsync("http://localhost/view.php", c);

            var str = await response.Content.ReadAsStringAsync();
            string s = str.ToString();
            
            Pushpin pushpin2 = new Pushpin();
            pushpin2.Text = "2";
            MapLayer.SetPosition(pushpin2, new Location(14.27590, 101.29100));
            Map.Children.Add(pushpin2);


            if (s.Equals("Not Found"))
            {

            }
            else
            {
                var o = JArray.Parse(s);
                int i = 0;
                while (i < o.Count)
                {
                    Post tmp = new Post();
                    tmp.p_id = (int)o[i]["p_id"];
                    tmp.latitude = (double)o[i]["latitude"];
                    tmp.longtitude = (double)o[i]["longtitude"];
                    tmp.dateTime = (string)o[i]["date_time"];
                    tmp.id = (int)o[i]["id"];
                    tmp.description = (string)o[i]["description"];
                    tmp.status = (int)o[i]["status"];
                    tmp.countSolve = (int)o[i]["count_solved"];
                    tmp.countSeen = (int)o[i]["count_seen"];
                    tmp.countSpam = (int)o[i]["count_spam"];
                    tmp.nameTag.Add((string)o[i]["nametag"]);
                    i++;
                    if (tmp.id != (int)o[i]["p_id"])
                    {
                        post.Add(tmp);
                        continue;
                    }
                    else
                    {
                        while (tmp.id == (int)o[i]["p_id"])
                        {
                            tmp.nameTag.Add((string)o[i]["nametag"]);
                            i++;
                        }
                        post.Add(tmp);

                    }
                }

                
                

        



            }
                

        }