daily pastebin goal
28%
SHARE
TWEET

Untitled

a guest Dec 10th, 2018 65 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. public class Service
  2. {
  3.     HttpClient client;
  4.  
  5.     public Service()
  6.     {
  7.         client = new HttpClient();
  8.         client.MaxResponseContentBufferSize = 256000;
  9.     }
  10.  
  11.     public async Task<ObservableCollection<TodoItem>> DataAsync(int id, string dist)
  12.     {
  13.         string Json = "https://api...." + id + "&dist=" + dist;
  14.         try
  15.         {
  16.             var response = await client.GetAsync(Json);
  17.             if (response.IsSuccessStatusCode)
  18.             {
  19.                 var content = await response.Content.ReadAsStringAsync();
  20.                 ObservableCollection<TodoItem> stations = JsonConvert.DeserializeObject<ObservableCollection<TodoItem>>(content);
  21.                 Debug.WriteLine(content);
  22.                 return stations;
  23.             }
  24.             else
  25.             {
  26.                 return null;
  27.             }
  28.         }
  29.         catch (HttpRequestException e)
  30.         {
  31.             Debug.WriteLine("nException Caught!");
  32.             Debug.WriteLine("Message :{0} ", e.Message);
  33.             return null;
  34.         }
  35.     }
  36. }
  37.    
  38. public async Task Get()
  39.     {
  40.         var PinDataAsync = await _Service.DataAsync(Item.id, "5000");
  41.  
  42.         try
  43.         {
  44.             foreach (var i in PinDataAsync)
  45.             {
  46.                 var pin = new Pin
  47.                 {
  48.                     Type = PinType.Place,
  49.                     Position = new Position(i.lat, i.lon),
  50.                     Label = i.name
  51.                 };
  52.                 Map.Pins.Add(pin);
  53.             }
  54.         }
  55.         catch (Exception err)
  56.         {
  57.             Debug.WriteLine("Error {0}", err);
  58.         }
  59.     }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top