Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class Service
- {
- HttpClient client;
- public Service()
- {
- client = new HttpClient();
- client.MaxResponseContentBufferSize = 256000;
- }
- public async Task<ObservableCollection<TodoItem>> DataAsync(int id, string dist)
- {
- string Json = "https://api...." + id + "&dist=" + dist;
- try
- {
- var response = await client.GetAsync(Json);
- if (response.IsSuccessStatusCode)
- {
- var content = await response.Content.ReadAsStringAsync();
- ObservableCollection<TodoItem> stations = JsonConvert.DeserializeObject<ObservableCollection<TodoItem>>(content);
- Debug.WriteLine(content);
- return stations;
- }
- else
- {
- return null;
- }
- }
- catch (HttpRequestException e)
- {
- Debug.WriteLine("nException Caught!");
- Debug.WriteLine("Message :{0} ", e.Message);
- return null;
- }
- }
- }
- public async Task Get()
- {
- var PinDataAsync = await _Service.DataAsync(Item.id, "5000");
- try
- {
- foreach (var i in PinDataAsync)
- {
- var pin = new Pin
- {
- Type = PinType.Place,
- Position = new Position(i.lat, i.lon),
- Label = i.name
- };
- Map.Pins.Add(pin);
- }
- }
- catch (Exception err)
- {
- Debug.WriteLine("Error {0}", err);
- }
- }
Add Comment
Please, Sign In to add comment