private async void GoButtonClickedAsync() { goStation.Visibility = ViewStates.Invisible; if (isThereAPoli == true) { GMap.Clear(); foreach (var point in points) { AddNewPoint(point.Name, point.Latitude, point.Longitude, point.Info.Replace(",", ",\n")); } LatLng latlng = new LatLng(Convert.ToDouble(latitude), Convert.ToDouble(longitude)); var options = new MarkerOptions().SetPosition(latlng).SetTitle("You").SetIcon(BitmapDescriptorFactory.DefaultMarker(BitmapDescriptorFactory.HueAzure)); locationMarker = GMap.AddMarker(options); } string url = "https://maps.googleapis.com/maps/api/directions/json?origin=" + latitude + "," + longitude + "&destination=" + x + "," + y + "&key=AIzaSyBeT4UxwuGgyndiaiagBgY-thD09SvOEGE"; string json = await FetchGoogleDataAsync(url); Log.Error("lv", json); DirectionsDto directions = JsonConvert.DeserializeObject <DirectionsDto>(json); var lstDecodedPoints = FnDecodePolylinePoints(directions.routes[0].overview_polyline.points); var latLngPoints = new LatLng[lstDecodedPoints.Count]; int index = 0; foreach (Android.Locations.Location loc in lstDecodedPoints) { latLngPoints[index++] = new LatLng(loc.Latitude, loc.Longitude); } // Create polyline PolylineOptions polylineoption = new PolylineOptions(); polylineoption.InvokeColor(Android.Graphics.Color.Green); polylineoption.Geodesic(true); polylineoption.Add(latLngPoints); isThereAPoli = true; // Add polyline to map this.RunOnUiThread(() => GMap.AddPolyline(polylineoption)); CameraUpdate camera = CameraUpdateFactory.NewLatLngZoom(MidPoint(Convert.ToDouble(latitude), Convert.ToDouble(longitude), x, y), 11); GMap.MoveCamera(camera); goNavigate.Visibility = ViewStates.Visible; }
private async void GoPlanButtonClickedAsync() { goPlan.Visibility = ViewStates.Invisible; goStation.Visibility = ViewStates.Invisible; goDestination.Visibility = ViewStates.Invisible; goNavigate.Visibility = ViewStates.Invisible; plan = true; nearest = false; string url = "https://maps.googleapis.com/maps/api/directions/json?origin=" + startLat + "," + startLng + "&destination=" + destinationLat + "," + destinationLng + "&key=AIzaSyBeT4UxwuGgyndiaiagBgY-thD09SvOEGE"; string json = await FetchGoogleDataAsync(url); Log.Error("lv", json); DirectionsDto directions = JsonConvert.DeserializeObject <DirectionsDto>(json); var lstDecodedPoints = FnDecodePolylinePoints(directions.routes[0].overview_polyline.points); var latLngPoints = new LatLng[lstDecodedPoints.Count]; int index = 0; foreach (Android.Locations.Location loc in lstDecodedPoints) { latLngPoints[index++] = new LatLng(loc.Latitude, loc.Longitude); } // Create polyline PolylineOptions polylineoption = new PolylineOptions(); polylineoption.InvokeColor(Android.Graphics.Color.Green); polylineoption.Geodesic(true); polylineoption.Add(latLngPoints); isThereAPoli = true; // Add polyline to map this.RunOnUiThread(() => GMap.AddPolyline(polylineoption)); CameraUpdate camera = CameraUpdateFactory.NewLatLngZoom(MidPoint(Convert.ToDouble(startLat), Convert.ToDouble(startLng), x, y), 8); GMap.MoveCamera(camera); goNavigate.Visibility = ViewStates.Visible; }
public async Task AddStationToRoute() { string json; if (plan == false) { if (waypoints.Equals("0")) { waypoints = x + "," + y; } else { waypoints = waypoints + "|" + x + "," + y; } AddButton.Visibility = ViewStates.Invisible; string url = "https://maps.googleapis.com/maps/api/directions/json?origin=" + latitude + "," + longitude + "&destination=" + destinationLat + "," + destinationLng + "&waypoints=" + waypoints + "&key=AIzaSyBeT4UxwuGgyndiaiagBgY-thD09SvOEGE"; json = await FetchGoogleDataAsync(url); GMap.Clear(); //location LatLng latlng = new LatLng(Convert.ToDouble(latitude), Convert.ToDouble(longitude)); var options = new MarkerOptions().SetPosition(latlng).SetTitle("You").SetIcon(BitmapDescriptorFactory.DefaultMarker(BitmapDescriptorFactory.HueAzure)); locationMarker = GMap.AddMarker(options); //destination LatLng destination = new LatLng(Convert.ToDouble(destinationLat), Convert.ToDouble(destinationLng)); MarkerOptions options1 = new MarkerOptions().SetPosition(destination).SetTitle(editText.Text).SetSnippet("Destination").SetIcon(BitmapDescriptorFactory.DefaultMarker(BitmapDescriptorFactory.HueAzure)); GMap.AddMarker(options1); } else { if (waypoints.Equals("0")) { waypoints = x + "," + y; } else { waypoints = waypoints + "|" + x + "," + y; } AddButton.Visibility = ViewStates.Invisible; string url = "https://maps.googleapis.com/maps/api/directions/json?origin=" + startLat + "," + startLng + "&destination=" + destinationLat + "," + destinationLng + "&waypoints=" + waypoints + "&key=AIzaSyBeT4UxwuGgyndiaiagBgY-thD09SvOEGE"; json = await FetchGoogleDataAsync(url); GMap.Clear(); //location LatLng latlng = new LatLng(Convert.ToDouble(startLat), Convert.ToDouble(startLng)); var options = new MarkerOptions().SetPosition(latlng).SetTitle("Start").SetIcon(BitmapDescriptorFactory.DefaultMarker(BitmapDescriptorFactory.HueAzure)); Marker DestinationMarker = GMap.AddMarker(options); //destination LatLng destination = new LatLng(Convert.ToDouble(destinationLat), Convert.ToDouble(destinationLng)); MarkerOptions options1 = new MarkerOptions().SetPosition(destination).SetTitle("Destination").SetSnippet("Destination").SetIcon(BitmapDescriptorFactory.DefaultMarker(BitmapDescriptorFactory.HueAzure)); GMap.AddMarker(options1); } //stations foreach (var point in viaPointsToDestination) { AddNewPoint(point.Name, point.Latitude, point.Longitude, point.Info.Replace(", ", "\n")); } DirectionsDto directions = JsonConvert.DeserializeObject <DirectionsDto>(json); var lstDecodedPoints = FnDecodePolylinePoints(directions.routes[0].overview_polyline.points); var latLngPoints = new LatLng[lstDecodedPoints.Count]; int index = 0; foreach (Android.Locations.Location loc in lstDecodedPoints) { latLngPoints[index++] = new LatLng(loc.Latitude, loc.Longitude); } // Create polyline PolylineOptions polylineoption = new PolylineOptions(); polylineoption.InvokeColor(Android.Graphics.Color.Green); polylineoption.Geodesic(true); polylineoption.Add(latLngPoints); isThereAPoli = true; // Add polyline to map this.RunOnUiThread(() => GMap.AddPolyline(polylineoption)); }