Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public int Heuristic(int goal, int next)
- {
- string url = $"https://maps.googleapis.com/maps/api/directions/json?origin={_dict[goal]}&destination={_dict[next]}&key=AIzaSyDH2GPpmav9YpqRI3RqIJBR9jgRdWxNeOE";
- WebRequest webRequest = WebRequest.Create(url);
- WebResponse webResponse = webRequest.GetResponse();
- string res = new StreamReader(webResponse.GetResponseStream())
- .ReadToEnd();
- var v = res.Split(new char[] {'{', '}'});
- var fromCoords = v[18]
- .Replace(':', ' ')
- .Replace(" ", "")
- .Replace("\n", "")
- .Replace("\"", " ")
- .Replace(",", "")
- .Replace(".", ",")
- .Split(' ');
- var toCoords = v[20]
- .Replace(':', ' ')
- .Replace(" ", "")
- .Replace("\n", "")
- .Replace("\"", " ")
- .Replace(",", "")
- .Replace(".", ",")
- .Split(' ');
- double [,]matrix= new double[2,2];
- matrix[0, 0] = Convert.ToDouble(fromCoords[2]);
- matrix[0, 1] = Convert.ToDouble(fromCoords[4]);
- matrix[1, 0] = Convert.ToDouble(toCoords[2]);
- matrix[1, 1] = Convert.ToDouble(toCoords[4]);
- var dist = Math.Pow(matrix[0, 0] - matrix[1, 0], 2) + Math.Pow(matrix[0, 1] - matrix[1, 1], 2);
- return (int) (111 * dist);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement