public void UpdateAllPOIAddresses() { Geofence g = new Geofence(); using (SqlConnection con = new SqlConnection(DBHelper.DBConnectionstring)) { con.Open(); SqlCommand cmd = new SqlCommand("Select lat, lng, id from pos", con); SqlDataReader dr = cmd.ExecuteReader(); while (dr.Read()) { double lat = (double)dr[0]; double lng = (double)dr[1]; int id = (int)dr[2]; Address a = g.GetPOI(lat, lng); if (a == null) { continue; } using (SqlConnection con2 = new SqlConnection(DBHelper.DBConnectionstring)) { con2.Open(); SqlCommand cmd2 = new SqlCommand("update pos set address=@address where id = @id", con2); cmd2.Parameters.AddWithValue("@id", id); cmd2.Parameters.AddWithValue("@address", a.name); cmd2.ExecuteNonQuery(); } } } }
public void TestMethodGeocode() { ServicePointManager.Expect100Continue = true; ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12; var geofence = new TeslaLogger.Geofence(false); var a = geofence.GetPOI(48.456708, 10.029897); Assert.AreEqual(a.name, "Supercharger DE-Ulm"); a = geofence.GetPOI(48.456616, 10.030200); Assert.AreEqual(a.name, "Supercharger DE-Ulm"); a = geofence.GetPOI(48.456790, 10.030014); Assert.AreEqual(a.name, "Supercharger DE-Ulm"); a = geofence.GetPOI(48.456691, 10.030241); Assert.AreEqual(a.name, "Supercharger DE-Ulm"); a = geofence.GetPOI(48.456888, 10.029635); Assert.AreEqual(a.name, "EnBW DE-Ulm"); GeocodeCache.Instance.ClearCache(); Car c = new Car(0, "", "", 0, "", DateTime.Now, "", "", "", "", "", "", null); string temp = WebHelper.ReverseGecocodingAsync(c, 35.677121, 139.751033).Result; Assert.AreEqual("jp-100-0013 千代田区, 内堀通り ", temp); Assert.AreEqual("jp", c.currentJSON.current_country_code); Assert.AreEqual("", c.currentJSON.current_state); temp = WebHelper.ReverseGecocodingAsync(c, 48.400892, 9.970095).Result; Assert.AreEqual("89077 Ulm, Beringerbrücke ", temp); Assert.AreEqual("de", c.currentJSON.current_country_code); Assert.AreEqual("Baden-Württemberg", c.currentJSON.current_state); temp = WebHelper.ReverseGecocodingAsync(c, 40.773667, -74.039867).Result; Assert.AreEqual("us-07047 North Bergen, Jane Street ", temp); Assert.AreEqual("us", c.currentJSON.current_country_code); Assert.AreEqual("New Jersey", c.currentJSON.current_state); }
public void TestMethodGeocode() { var geofence = new TeslaLogger.Geofence(); var a = geofence.GetPOI(48.456708, 10.029897); Assert.AreEqual(a.name, "Supercharger DE-Ulm"); a = geofence.GetPOI(48.456616, 10.030200); Assert.AreEqual(a.name, "Supercharger DE-Ulm"); a = geofence.GetPOI(48.456790, 10.030014); Assert.AreEqual(a.name, "Supercharger DE-Ulm"); a = geofence.GetPOI(48.456691, 10.030241); Assert.AreEqual(a.name, "Supercharger DE-Ulm"); a = geofence.GetPOI(48.456888, 10.029635); Assert.AreEqual(a.name, "EnBW DE-Ulm"); string temp = WebHelper.ReverseGecocodingAsync(35.677121, 139.751033).Result; Assert.AreEqual(temp, "警視庁, jp-100-0013 千代田区, 内堀通り "); }
public void TestMethodGeocode() { var geofence = new TeslaLogger.Geofence(false); var a = geofence.GetPOI(48.456708, 10.029897); Assert.AreEqual(a.name, "Supercharger DE-Ulm"); a = geofence.GetPOI(48.456616, 10.030200); Assert.AreEqual(a.name, "Supercharger DE-Ulm"); a = geofence.GetPOI(48.456790, 10.030014); Assert.AreEqual(a.name, "Supercharger DE-Ulm"); a = geofence.GetPOI(48.456691, 10.030241); Assert.AreEqual(a.name, "Supercharger DE-Ulm"); a = geofence.GetPOI(48.456888, 10.029635); Assert.AreEqual(a.name, "EnBW DE-Ulm"); GeocodeCache.Instance.ClearCache(); string temp = WebHelper.ReverseGecocodingAsync(35.677121, 139.751033).Result; Assert.AreEqual("jp-100-0013 千代田区, 内堀通り ", temp); Assert.AreEqual("jp", DBHelper.currentJSON.current_country_code); Assert.AreEqual("", DBHelper.currentJSON.current_state); temp = WebHelper.ReverseGecocodingAsync(48.400892, 9.970095).Result; Assert.AreEqual("89077 Ulm, Beringerbrücke ", temp); Assert.AreEqual("de", DBHelper.currentJSON.current_country_code); Assert.AreEqual("Baden-Württemberg", DBHelper.currentJSON.current_state); temp = WebHelper.ReverseGecocodingAsync(40.773667, -74.039867).Result; Assert.AreEqual("us-07047 , Jane Street ", temp); Assert.AreEqual("us", DBHelper.currentJSON.current_country_code); Assert.AreEqual("New Jersey", DBHelper.currentJSON.current_state); }
public async Task <string> ReverseGecocodingAsync(double latitude, double longitude) { string url = ""; string resultContent = ""; try { Address a = null; a = geofence.GetPOI(latitude, longitude); if (a != null) { return(a.name); } Tools.SetThread_enUS(); WebClient webClient = new WebClient(); webClient.Headers.Add("User-Agent: TeslaLogger"); webClient.Encoding = Encoding.UTF8; url = "http://nominatim.openstreetmap.org/reverse?format=jsonv2&lat="; url += latitude.ToString(); url += "&lon="; url += longitude.ToString(); resultContent = await webClient.DownloadStringTaskAsync(new Uri(url)); object jsonResult = new JavaScriptSerializer().DeserializeObject(resultContent); var r1 = ((System.Collections.Generic.Dictionary <string, object>)jsonResult)["address"]; var r2 = (System.Collections.Generic.Dictionary <string, object>)r1; string postcode = ""; if (r2.ContainsKey("postcode")) { postcode = r2["postcode"].ToString(); } var country_code = r2["country_code"].ToString(); string road = ""; if (r2.ContainsKey("road")) { road = r2["road"].ToString(); } string city = ""; if (r2.ContainsKey("city")) { city = r2["city"].ToString(); } else if (r2.ContainsKey("village")) { city = r2["village"].ToString(); } else if (r2.ContainsKey("town")) { city = r2["town"].ToString(); } string house_number = ""; if (r2.ContainsKey("house_number")) { house_number = r2["house_number"].ToString(); } var name = ""; if (r2.ContainsKey("name") && r2["name"] != null) { name = r2["name"].ToString(); } var address29 = ""; if (r2.ContainsKey("address29") && r2["address29"] != null) { address29 = r2["address29"].ToString(); } string adresse = ""; if (address29.Length > 0) { adresse += address29 + ", "; } if (country_code != "de") { adresse += country_code + "-"; } adresse += postcode + " " + city + ", " + road + " " + house_number; if (name.Length > 0) { adresse += " / " + name; } System.Diagnostics.Debug.WriteLine(url + "\r\n" + adresse); return(adresse); } catch (Exception ex) { if (url == null) { url = "NULL"; } if (resultContent == null) { resultContent = "NULL"; } Tools.ExceptionWriter(ex, url + "\r\n" + resultContent); } return(""); }