// https://github.com/maximn/google-maps public List <string> getDirection(Location L) { List <string> steps = new List <string>(); DirectionsRequest directionsRequest = new DirectionsRequest() { Origin = this.lat + "," + this.lon, Destination = L.lat + "," + L.lon }; directionsRequest.ApiKey = this.API_KEY; DirectionsResponse directionsResponse = GoogleMapsApi.GoogleMaps.Directions.Query(directionsRequest); GoogleMapsApi.Entities.Directions.Response.Leg leg = directionsResponse.Routes.ElementAt(0).Legs.ElementAt(0); foreach (var step in leg.Steps) { steps.Add(Regex.Replace(step.HtmlInstructions, @"<(.|\n)*?>", string.Empty)); } return(steps); }
public List <GoogleMapsApi.Entities.Common.Location> getPolyline(Location L) { List <GoogleMapsApi.Entities.Common.Location> steps = new List <GoogleMapsApi.Entities.Common.Location>(); DirectionsRequest directionsRequest = new DirectionsRequest() { Origin = this.lat + "," + this.lon, Destination = L.lat + "," + L.lon }; directionsRequest.ApiKey = this.API_KEY; DirectionsResponse directionsResponse = GoogleMapsApi.GoogleMaps.Directions.Query(directionsRequest); GoogleMapsApi.Entities.Directions.Response.Leg leg = directionsResponse.Routes.ElementAt(0).Legs.ElementAt(0); foreach (var step in leg.Steps) { foreach (GoogleMapsApi.Entities.Common.Location point in step.PolyLine.Points) { steps.Add(point); } } return(steps); }
private void CalculateButton_Click(object sender, RoutedEventArgs e) { StatusListEdit.Items.Clear(); string destAddress; Double[] distances = new double[stations.Length]; string[] durations = new string[stations.Length]; int c, location = 1; double minimum; if (AddressTextEdit.Text == "") { WinUIMessageBox.Show("Please! Enter a destination address.", "Destination field is empty", MessageBoxButton.OK, MessageBoxImage.Error); } else { StatusListEdit.Items.Add("Calculating distance..."); destAddress = AddressTextEdit.Text; for (int i = 0; i < stations.Length; i++) { DirectionsRequest directionsRequest2 = new DirectionsRequest() { Origin = stations[i], Destination = destAddress, }; DirectionsResponse directionsResponse = GoogleMapsApi.GoogleMaps.Directions.Query(directionsRequest2); GoogleMapsApi.Entities.Directions.Response.Leg leg = directionsResponse.Routes.ElementAt(0).Legs.ElementAt(0); StatusListEdit.Items.Add(string.Format("Distance from: {0} to {1} is {2} will take {3}", stations[i], destAddress, leg.Distance.Text, leg.Duration.Text)); distances[i] = Convert.ToDouble(leg.Distance.Text.Substring(0, leg.Distance.Text.Length - 3)); durations[i] = leg.Duration.Text; } minimum = distances[0]; for (c = 0; c < stations.Length; c++) { if (distances[c] < minimum) { minimum = distances[c]; location = c; } } StatusListEdit.Items.Add( string.Format("Station-{0} ({1}) has shortest distance from {2} of {3} km will take just {4}", location + 1, stations[location], destAddress, distances[location], durations[location])); Browser.Visibility = Visibility.Visible; Browser.InvokeScript("GetRouteAddress", new object[] { stations[location], destAddress }); if (client != null) { StatusListEdit.Items.Add(""); //byte[] bytes = new byte[1024]; //int bytesRead = ns.Read(bytes, 0, bytes.Length); //string m = Encoding.ASCII.GetString(bytes, 0, bytesRead); //Text = m; loc = stations[location] + "/" + destAddress; SendButton.Visibility = Visibility.Visible; } } //Browser.InvokeScript("calculateDistance", new string[] { station1, station2 }); //Browser.InvokeScript("GetRouteLatLong", new object[] { station1, 33.6141098, 72.9947294 }); }