public void returnInfo(int x, int y, out string content, out string name) { content = ""; name = ""; string sql = "SELECT * from landmark"; conn.Open(); SqlCommand cmd = new SqlCommand(sql, conn); cmd.ExecuteNonQuery(); SqlDataReader dd = cmd.ExecuteReader(); while (dd.Read()) { double lat = Convert.ToDouble(dd["latitude"]); double lon = Convert.ToDouble(dd["longitude"]); int pixelX, pixelY; BingMaps.LatLongToPixelXY(lat, lon, MapView.level, out pixelX, out pixelY); pixelX -= MapView.mapX * 256; pixelY -= MapView.mapY * 256; if (x == pixelX && y == pixelY) { name = Convert.ToString(dd["name"]); content = Convert.ToString(dd["location"]) + "\r\n" + Convert.ToString(dd["telephone"]); } } conn.Close(); cmd.Dispose(); }
public bool findLocation(string locationName, out int returnx, out int returny, bool isFirst) { string sql = "SELECT * from landmark"; conn.Open(); SqlCommand cmd = new SqlCommand(sql, conn); cmd.ExecuteNonQuery(); SqlDataReader dd = cmd.ExecuteReader(); string s = ""; returnx = 0; returny = 0; while (dd.Read()) { s = Convert.ToString(dd["name"]).TrimEnd(); if (s.IndexOf(locationName) != -1) { if (isFirst == true) { MapView.level = 19; } BingMaps.LatLongToPixelXY(Convert.ToDouble(dd["latitude"]), Convert.ToDouble(dd["longitude"]), MapView.level, out returnx, out returny); conn.Close(); cmd.Dispose(); return(true); } } conn.Close(); cmd.Dispose(); return(false); }
public void isExist(double lat, double lon, double lat2, double lon2, out List <int> lati, out List <int> longi, out List <string> cate) { string sql = "SELECT latitude,longitude,category from landmark"; conn.Open(); SqlCommand cmd = new SqlCommand(sql, conn); cmd.ExecuteNonQuery(); SqlDataReader dd = cmd.ExecuteReader(); List <int> temp = new List <int>(), temp2 = new List <int>(); List <string> temp3 = new List <string>(); while (dd.Read()) { double d = Convert.ToDouble(dd["latitude"]), d2 = Convert.ToDouble(dd["longitude"]); if (clip(lat2, lat, d) && clip(lon, lon2, d2)) { int x, y; BingMaps.LatLongToPixelXY(d, d2, MapView.level, out x, out y); x -= MapView.mapX * 256; y -= MapView.mapY * 256; temp.Add(x); temp2.Add(y); temp3.Add(Convert.ToString(dd["category"])); } } lati = temp; longi = temp2; cate = temp3; conn.Close(); cmd.Dispose(); }
public static void drawPolygon() { int cnt = -1, arrayCnt = 0; string tmp = ""; Array.Resize(ref poi, 0); List <string> array = new List <string>(); List <string> array2 = new List <string>(); readFile("C:\\Users\\ColifeTNNB01\\Desktop\\maptest2\\題目\\Khsc_town.geo", out array); readFile("C:\\Users\\ColifeTNNB01\\Desktop\\maptest2\\題目\\Khsc_town.csv", out array2); arrayNum.Clear(); for (int i = 0; i < 42; i++) { string[] words = array2[i].Split(','); TownName.Add(words[4]); } for (int i = 0; i < 66; i++) { string[] words = array[i].Split(','); double[] intWords = new double[words.Length]; for (int k = 0; k < words.Length; k++) { intWords[k] = Convert.ToDouble(words[k]); } for (int j = 3; j + 1 < Convert.ToInt32(words[2]) * 2 + 3; j += 2) { BingMaps.LatLongToPixelXY(intWords[j + 1], intWords[j], MapView.level, out TownPixelX, out TownPixelY); cnt++; Array.Resize(ref poi, poi.Length + 1); poi[cnt] = new Point(TownPixelX, TownPixelY); } if (words[1] != tmp) { tmp = words[1]; if (i != 0) { arrayNum.Add(arrayCnt); } arrayCnt = 0; } arrayCnt += Convert.ToInt32(intWords[2]); if (i == 65) { arrayNum.Add(arrayCnt); } } forFlag = true; }
public static void drawLine() { List <string> array = new List <string>(); List <string> array2 = new List <string>(); readFile("C:\\Users\\ColifeTNNB01\\Desktop\\maptest2\\題目\\Khsc_mrt.geo", out array); readFile("C:\\Users\\ColifeTNNB01\\Desktop\\maptest2\\題目\\Khsc_mrt.csv", out array2); for (int i = 0; i < 107; i++) { string[] words = array[i].Split(','); string[] color = array2[i].Split(','); double[] intWords = new double[words.Length]; for (int k = 0; k < words.Length; k++) { intWords[k] = double.Parse(words[k]); } for (int j = 2; j + 3 < Convert.ToInt32(words[1]) * 2 + 2; j += 2) { BingMaps.LatLongToPixelXY(intWords[j + 1], intWords[j], MapView.level, out Form1.pixelX, out Form1.pixelY); BingMaps.LatLongToPixelXY(intWords[j + 3], intWords[j + 2], MapView.level, out Form1.pixelx, out Form1.pixely); drawX.Add(Form1.pixelX); drawY.Add(Form1.pixelY); drawx.Add(Form1.pixelx); drawy.Add(Form1.pixely); if (color[3] == "紅線") { red.Add(1); } else { red.Add(0); } cnt++; } } }
private void search(object sender, EventArgs e) { string address = textBox1.Text; int x, y; string requestUri = string.Format("http://maps.googleapis.com/maps/api/geocode/xml?address={0}&sensor=false", Uri.EscapeDataString(address)); XmlDocument doc = new XmlDocument(); doc.Load(requestUri); if (doc.SelectSingleNode("//status").InnerText == "OK") { XmlNodeList nodes = doc.SelectNodes("//location"); double lng = Convert.ToDouble(nodes[0].SelectSingleNode("lng").InnerText); double lat = Convert.ToDouble(nodes[0].SelectSingleNode("lat").InnerText); //string s = string.Format("logitude: {0} latitude: {1}", lng,lat); BingMaps.LatLongToPixelXY(lat, lng, 17, out x, out y); MapView.landmarkFocus(x, y); MessageBox.Show(Convert.ToString(doc.SelectSingleNode("//formatted_address").InnerText), "地理資訊"); this.Refresh(); } else { MessageBox.Show("找不到目標", "ERROR"); } }