// Generates the Travel Path from PoitnA to B - Under Working... private void button2_Click(object sender, EventArgs e) { try { button2.Text = "Working..."; int c = 0; // Creates a coordinate array to store the Path points Coordinate[] Coord = new Coordinate[listView1.Items.Count]; // Loads the stop list into the Coordinate array foreach (ListViewItem item in listView1.Items) { Coord[c] = new Coordinate(); Coord[c].Latitude = (int)(Convert.ToDouble(item.SubItems[5].Text) / 0.000001); // Convert from Double to Int Coord[c].Longitude = (int)(Convert.ToDouble(item.SubItems[6].Text) / 0.000001); c++; } // Call the WebService TravelPathResult r = RNA.WebServices.TravelPath(Coord); // Loads the result into the Location Class c = 0; AUX.Services.Location[] Loc = new AUX.Services.Location[r.Path.Points.Count()]; // Loads the returned points into the Location class required to build the KML file foreach (Coordinate p in r.Path.Points) // Load all points from the Path { Loc[c] = new AUX.Services.Location(); Loc[c].Lat = p.Latitude * 0.000001; // Convert from Int to Double Loc[c].Lon = p.Longitude * 0.000001; c++; } button2.Text = "Travel Path"; // Displays a SaveFileDialog SaveFileDialog saveFileDialog1 = new SaveFileDialog(); saveFileDialog1.InitialDirectory = Convert.ToString(Environment.SpecialFolder.MyDocuments); saveFileDialog1.FileName = "Route " + Route_Name + ".kml"; saveFileDialog1.DefaultExt = "*.kml"; saveFileDialog1.Filter = "KML File|*.kml"; saveFileDialog1.Title = "Export Travel Path to a KML File"; // If the file name returns OK if (saveFileDialog1.ShowDialog() == DialogResult.OK) { // Creates the KML file AUX.Services.CreateKML(saveFileDialog1.FileName, Loc); } } catch (Exception Ex) { MessageBox.Show(Ex.Message, "Error"); } }
// Exports the stops (Lat & Lon) to a KML file private void button1_Click(object sender, EventArgs e) { // Checks if the list is empty if (listView1.Items.Count > 0) { int c = 0; AUX.Services.Location[] Loc = new AUX.Services.Location[listView1.Items.Count]; // Loads the stop list into the Location class foreach (ListViewItem item in listView1.Items) { Loc[c] = new AUX.Services.Location(); Loc[c].Name = item.SubItems[3].Text; Loc[c].Address = item.SubItems[4].Text; Loc[c].Lat = Convert.ToDouble(item.SubItems[5].Text); Loc[c].Lon = Convert.ToDouble(item.SubItems[6].Text); c++; } // Displays a SaveFileDialog SaveFileDialog saveFileDialog1 = new SaveFileDialog(); saveFileDialog1.InitialDirectory = Convert.ToString(Environment.SpecialFolder.MyDocuments); saveFileDialog1.FileName = "Route " + Route_Name + ".kml"; saveFileDialog1.DefaultExt = "*.kml"; saveFileDialog1.Filter = "KML File|*.kml"; saveFileDialog1.Title = "Export Stops to a KML File"; // If the file name returns OK if (saveFileDialog1.ShowDialog() == DialogResult.OK) { // Creates the KML file AUX.Services.CreateKML(saveFileDialog1.FileName, Loc); } } else { MessageBox.Show("No stops to export.", "Warning"); } }
// Geocodes an serive location address private void button2_Click(object sender, EventArgs e) { if (listView2.Items.Count > 0) { // Clears Geocode address list listView3.Items.Clear(); try { button2.Text = "Working..."; // Loads the address data into the object Address address = new Address { AddressLine1 = textBox1.Text.Trim(), AddressLine2 = "", Locality = new Locality { AdminDivision1 = textBox3.Text.Trim(), // State AdminDivision2 = textBox2.Text.Trim(), // City CountryISO3Abbr = textBox5.Text, // Country PostalCode = textBox4.Text.Trim() } }; // RNA Geocoding int c = 0; char[] delimiterChars = { '|' }; foreach (String s in RNA.WebServices.Geocode(address)) { c++; string[] r = s.Split(delimiterChars); listView3.Items.Add(new ListViewItem(new string[] { c.ToString(), "RNA Maps", r[0], r[1], r[2], r[3], "-" })); } // Bing Geocoding if (checkBox1.Checked) { c++; AUX.Services.Location b = AUX.Services.SearchBing(textBox1.Text + " " + textBox2.Text + " " + textBox3.Text + " " + textBox4.Text + " " + textBox5.Text); listView3.Items.Add(new ListViewItem(new string[] { c.ToString(), "Bing Maps", b.Lat.ToString(), b.Lon.ToString(), "-", b.Quality, b.Address })); } // Google Geocoding if (checkBox2.Checked) { c++; AUX.Services.Location g = AUX.Services.SearchGoogle(textBox1.Text + " " + textBox2.Text + " " + textBox3.Text + " " + textBox4.Text + " " + textBox5.Text); listView3.Items.Add(new ListViewItem(new string[] { c.ToString(), "Google Maps", g.Lat.ToString(), g.Lon.ToString(), "-", g.Quality, g.Address })); } // Auto Size the Geocode Result listview columns AUX.Services.autoResizeColumns(listView3, 20); button2.Text = "Search"; } catch (Exception Ex) { MessageBox.Show(Ex.Message, "Error"); } } else { MessageBox.Show("No services loaded. Select one region first.", "Warning"); } }