SHARE
TWEET

Untitled

a guest May 19th, 2019 81 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.         public int Heuristic(int goal, int next)
  2.         {
  3.             string url = $"https://maps.googleapis.com/maps/api/directions/json?origin={_dict[goal]}&destination={_dict[next]}&key=AIzaSyDH2GPpmav9YpqRI3RqIJBR9jgRdWxNeOE";
  4.             WebRequest webRequest = WebRequest.Create(url);
  5.             WebResponse webResponse = webRequest.GetResponse();
  6.  
  7.             string res = new StreamReader(webResponse.GetResponseStream())
  8.                 .ReadToEnd();
  9.            
  10.             var v = res.Split(new char[] {'{', '}'});
  11.             var fromCoords = v[18]
  12.                 .Replace(':', ' ')
  13.                 .Replace(" ", "")
  14.                 .Replace("\n", "")
  15.                 .Replace("\"", " ")
  16.                 .Replace(",", "")
  17.                 .Replace(".", ",")
  18.                 .Split(' ');
  19.  
  20.             var toCoords = v[20]
  21.                 .Replace(':', ' ')
  22.                 .Replace(" ", "")
  23.                 .Replace("\n", "")
  24.                 .Replace("\"", " ")
  25.                 .Replace(",", "")
  26.                 .Replace(".", ",")
  27.                 .Split(' ');
  28.            
  29.             double [,]matrix=  new double[2,2];
  30.             matrix[0, 0] = Convert.ToDouble(fromCoords[2]);
  31.             matrix[0, 1] = Convert.ToDouble(fromCoords[4]);
  32.             matrix[1, 0] = Convert.ToDouble(toCoords[2]);
  33.             matrix[1, 1] = Convert.ToDouble(toCoords[4]);
  34.  
  35.             var dist = Math.Pow(matrix[0, 0] - matrix[1, 0], 2) + Math.Pow(matrix[0, 1] - matrix[1, 1], 2);
  36.             return (int) (111 * dist);
  37.         }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top