public static GoogleGeoCodeResponse ReverseGeocodeGetWholeResponse(double latitude, double longitude, string secretKey) { string temp = new System.Net.WebClient().DownloadString(string.Format(googleWebAddress, latitude, longitude)); byte[] response = Encoding.Unicode.GetBytes(temp); using (MemoryStream ms = new MemoryStream(response)) { var deserialiser = new DataContractJsonSerializer(typeof(GoogleGeoCodeResponse)); GoogleGeoCodeResponse result = (GoogleGeoCodeResponse)deserialiser.ReadObject(ms); return(result); } }
//private static string Sign(string url, string secretKey) //{ // if (!string.IsNullOrEmpty(ClientId)) // url += string.Format("&client={0}", ClientId); // if (!string.IsNullOrEmpty(secretKey)) // { // string usablePrivateKey = secretKey.Replace("-", "+").Replace("_", "/"); // byte[] privateKeyBytes = Convert.FromBase64String(usablePrivateKey); // Uri uri = new Uri(url); // byte[] encodedPathAndQueryBytes = System.Text.ASCIIEncoding.ASCII.GetBytes(uri.LocalPath + uri.Query); // // compute the hash // HMACSHA1 algorithm = new HMACSHA1(privateKeyBytes); // byte[] hash = algorithm.ComputeHash(encodedPathAndQueryBytes); // // convert the bytes to string and make url-safe by replacing '+' and '/' characters // string signature = Convert.ToBase64String(hash).Replace("+", "-").Replace("/", "_"); // // Add the signature to the existing URI. // return uri.Scheme + "://" + uri.Host + uri.LocalPath + uri.Query + "&signature=" + signature; // } // return url; //} private static string ProcessResult(GoogleGeoCodeResponse result, out bool success) { //if (result.status.Equals("OK", StringComparison.InvariantCultureIgnoreCase)) //{ // if (result.results.Length > 0) // { // success = true; // var streetRecord = from r in result.results // where r.types.Contains("street_address") // select r.formatted_address; // if (streetRecord.Count() > 0) // return streetRecord.First(); // var routeRecord = from r in result.results // where r.types.Contains("route") // select r.formatted_address; // if (routeRecord.Count() > 0) // return routeRecord.First(); // var intersectionRecord = from r in result.results // where r.types.Contains("intersection") // select r.formatted_address; // if (intersectionRecord.Count() > 0) // return intersectionRecord.First(); // var postal_codeRecord = from r in result.results // where r.types.Contains("postal_code") // select r.formatted_address; // if (postal_codeRecord.Count() > 0) // return postal_codeRecord.First(); // return result.results[0].formatted_address; // } //} success = false; return(result.status); }