public void Restore() { XmlSerializer x = new XmlSerializer(typeof(SaveLoad)); FileStream reader = new FileStream("settings.xml", FileMode.Open); SaveLoad temp = (SaveLoad)x.Deserialize(reader); this.Address = temp.Address; this.Coordinates = temp.Coordinates; }
public void Save(string address, Geo geo) { this.Address = address; this.Coordinates = geo; XmlSerializer x = new XmlSerializer(typeof(SaveLoad)); TextWriter writer = new StreamWriter("settings.xml"); x.Serialize(writer, this); }
private static async Task <string> GetWheather(Geo data) { HttpClient httpClient = new HttpClient(); string key = "[" + DarkSky_API_Key + "]/"; string coord = data.Location.Lat.ToString().Replace(',', '.') + "," + data.Location.Lng.ToString().Replace(',', '.'); var response = await httpClient.GetAsync("https://api.darksky.net/forecast/" + DarkSky_API_Key + "/" + coord + "?units=si"); string content = await response.Content.ReadAsStringAsync(); return(content); }
private static async Task <string> GetCity(Geo data) { HttpClient httpClient = new HttpClient(); string myJson = "latlng=" + data.Location.Lat.ToString().Replace(',', '.') + "," + data.Location.Lng.ToString().Replace(',', '.') + "&" + "key=" + Google_API_Key; var response = await httpClient.PostAsync("https://maps.googleapis.com/maps/api/geocode/json?" + myJson, null); string content = await response.Content.ReadAsStringAsync(); return(content); }
private async void button1_Click(object sender, EventArgs e) { textBox1.Text = "..."; var response = await GetGeoData(); Geo coordinates = JsonConvert.DeserializeObject <Geo>(response); response = await GetCity(coordinates); Adresas adresai = JsonConvert.DeserializeObject <Adresas>(response); string adresas = adresai.Results[1].FormattedAddress.ToString(); UpdateLocationTextbox(coordinates, adresas); SaveLoad save = new SaveLoad(); save.Save(adresas, coordinates); }
private void UpdateLocationTextbox(Geo coordinates, string adresas) { var coordinates_string = coordinates.Location.Lat.ToString().Replace(',', '.') + ", " + coordinates.Location.Lng.ToString().Replace(',', '.'); textBox1.Text = adresas + " (" + coordinates_string + ")"; }