Created
January 1, 2012 00:32
-
-
Save adamdilek/1545763 to your computer and use it in GitHub Desktop.
c# Example for Location API
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| using System; | |
| using System.Collections.Generic; | |
| using System.ComponentModel; | |
| using System.Data; | |
| using System.Drawing; | |
| using System.Linq; | |
| using System.Text; | |
| using System.Windows.Forms; | |
| using System.Web; | |
| using System.Net; | |
| using System.IO; | |
| using Newtonsoft.Json; | |
| using Newtonsoft.Json.Linq; | |
| using System.Collections; | |
| namespace locationApi | |
| { | |
| public partial class Form1 : Form | |
| { | |
| ArrayList cities_id = new ArrayList(); | |
| ArrayList districts_id = new ArrayList(); | |
| ArrayList regions_id = new ArrayList(); | |
| public Form1() | |
| { | |
| InitializeComponent(); | |
| } | |
| private void Form1_Load(object sender, EventArgs e) | |
| { | |
| string responseFromServer = pigonLocationApi("http://pigon.ws/location/cities"); | |
| List<Query> cities = (List<Query>)JsonConvert.DeserializeObject(responseFromServer, typeof(List<Query>)); | |
| foreach (Query obj in cities) | |
| { | |
| comboBox1.Items.Add(obj.name); | |
| cities_id.Add(obj.id); | |
| } | |
| } | |
| public string pigonLocationApi(string Url) | |
| { | |
| string requestUri = String.Format(Url); | |
| HttpWebRequest request = (HttpWebRequest)WebRequest.Create(requestUri); | |
| Stream dataStream; | |
| WebResponse response = request.GetResponse(); | |
| dataStream = response.GetResponseStream(); | |
| StreamReader reader = new StreamReader(dataStream); | |
| string responseFromServer = reader.ReadToEnd(); | |
| reader.Close(); | |
| dataStream.Close(); | |
| response.Close(); | |
| return responseFromServer; | |
| } | |
| private void comboBox1_SelectedIndexChanged(object sender, EventArgs e) | |
| { | |
| districts_id.Clear(); | |
| comboBox2.Items.Clear(); | |
| regions_id.Clear(); | |
| comboBox3.Items.Clear(); | |
| int cityId = int.Parse(cities_id[comboBox1.SelectedIndex].ToString()); | |
| string responseFromServer = pigonLocationApi("http://pigon.ws/location/districts?city_id=" + cityId); | |
| List<Query> districts = (List<Query>)JsonConvert.DeserializeObject(responseFromServer, typeof(List<Query>)); | |
| foreach (Query obj in districts) | |
| { | |
| comboBox2.Items.Add(obj.name); | |
| districts_id.Add(obj.id); | |
| } | |
| } | |
| private void comboBox2_SelectedIndexChanged(object sender, EventArgs e) | |
| { | |
| regions_id.Clear(); | |
| comboBox3.Items.Clear(); | |
| int districtId = int.Parse(districts_id[comboBox2.SelectedIndex].ToString()); | |
| string responseFromServer = pigonLocationApi("http://pigon.ws/location/regions?district_id=" + districtId); | |
| List<Query> regions = (List<Query>)JsonConvert.DeserializeObject(responseFromServer, typeof(List<Query>)); | |
| foreach (Query obj in regions) | |
| { | |
| comboBox3.Items.Add(obj.name); | |
| regions_id.Add(obj.id); | |
| } | |
| } | |
| private void comboBox3_SelectedIndexChanged(object sender, EventArgs e) | |
| { | |
| comboBox4.Items.Clear(); | |
| int regionId = int.Parse(regions_id[comboBox3.SelectedIndex].ToString()); | |
| string responseFromServer = pigonLocationApi("http://pigon.ws/location/streets?region_id=" + regionId); | |
| List<Query> streets = (List<Query>)JsonConvert.DeserializeObject(responseFromServer, typeof(List<Query>)); | |
| foreach (Query obj in streets) | |
| { | |
| comboBox4.Items.Add(obj.name); | |
| } | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment