public static string GetCurrentAddress() { var latlong = GetCurrentLocation(); if (latlong != "autoip") { var strLatitude = latlong.Substring(0, latlong.IndexOf(',')); strLatitude = strLatitude.Trim(','); var strLongitude = latlong.Substring(latlong.IndexOf(',')); strLongitude = strLongitude.TrimStart(','); WebClient client = new WebClient(); client.Encoding = Encoding.UTF8; string Url = "http://maps.googleapis.com/maps/api/geocode/json?latlng=" + strLatitude + "," + strLongitude + "&sensor=true"; var getResult = client.DownloadString(Url); JObject parseJson = JObject.Parse(getResult); var getJsonres = parseJson["results"][0]; //var getJson = getJsonres["address_components"][1]; var getAddress = getJsonres["formatted_address"]; string Address = AccentsRemover.RemoveAccents(getAddress.ToString()); return(Address); } else { return(null); } }
public static Dictionary <string, string> GetWolframAlphaKnowledge(string q) { Dictionary <string, string> result = new Dictionary <string, string>(); string url = "http://api.wolframalpha.com/v1/spoken?input=" + q + "&appid=" + WAK2 + LocationParameter(); HttpWebRequest connection = (HttpWebRequest)WebRequest.Create(url); HttpWebResponse response; string responseFromServer = null; try { response = (HttpWebResponse)connection.GetResponse(); // Get the stream containing content returned by the server. Stream dataStream = response.GetResponseStream(); // Open the stream using a StreamReader for easy access. StreamReader reader = new StreamReader(dataStream); // Read the content. responseFromServer = reader.ReadToEnd(); // Clean up the streams and the response. if (response.StatusCode != HttpStatusCode.OK) { reader.Close(); response.Close(); } reader.Close(); response.Close(); } catch { } if (responseFromServer != null && responseFromServer.Contains("Information about")) { responseFromServer = responseFromServer.Replace("Information about", ""); var kg = GetGoogleKnowledge(q); if (kg != null) { responseFromServer = kg["data"]; result.Add("imageurl", kg["imageurl"]); } } result.Add("response", AccentsRemover.RemoveAccents(responseFromServer)); q = WebUtility.UrlEncode(q); string uri = (@"https://api.wolframalpha.com/v2/simple?input=" + q + "&appid=" + WAK1 + "&fontsize=12&width=330"); result.Add("simpleurl", uri); return(result); }
public static Dictionary <string, string> GetGoogleKnowledge(string s) { string url = "https://kgsearch.googleapis.com/v1/entities:search?query=" + s + "&key=" + KGK + "&limit=1&indent=True" + LocationParameter(); HttpWebRequest connection = (HttpWebRequest)WebRequest.Create(url); connection.ContentType = "application/json"; HttpWebResponse response; try { response = (HttpWebResponse)connection.GetResponse(); // Get the stream containing content returned by the server. Stream dataStream = response.GetResponseStream(); // Open the stream using a StreamReader for easy access. StreamReader reader = new StreamReader(dataStream); // Read the content. string responseFromServer = reader.ReadToEnd(); // Clean up the streams and the response. if (response.StatusCode != HttpStatusCode.OK) { reader.Close(); response.Close(); return(null); } reader.Close(); response.Close(); JObject parseJson = JObject.Parse(responseFromServer); var getlist = parseJson["itemListElement"]; Console.WriteLine(); var getdetail = getlist[0]["result"]["detailedDescription"]["articleBody"]; string result = getdetail.ToString(); int count = 0; Dictionary <string, string> final = new Dictionary <string, string>(); var imageurl = getlist[0]["result"]["image"]["contentUrl"].ToString(); final.Add("imageurl", imageurl); for (int i = 0; i < result.Length; i++) { if (result[i] == '.') { count++; } if (count == 3) { final.Add("data", AccentsRemover.RemoveAccents(result.Remove(i + 1))); return(final); } } final.Add("data", AccentsRemover.RemoveAccents(result)); return(final); } catch { return(null); } //catch { return null; } //} }