private async void Map_PinDragEnd(object sender, PinDragEventArgs e) { if (e.Pin.Label == Constants.ORIGEN_LABEL) { Start = new Geocode(e.Pin.Position.Latitude, e.Pin.Position.Longitude); Origin = await googleMapsApi.GetAddress(Start.StringLat(), Start.StringLng()); SetOneDirection(); } else { End = new Geocode(e.Pin.Position.Latitude, e.Pin.Position.Longitude); Destination = await googleMapsApi.GetAddress(End.StringLat(), End.StringLng()); } DrawRoute(); }
private async void DrawRoute() { SetOneDirection(); if (Start != null && End != null && Start != End) { Device.BeginInvokeOnMainThread(() => IsBusyOnMap = true); //IsBusy = true; var direction = await googleMapsApi.GetDirections( Start.StringLat(), Start.StringLng(), End.StringLat(), End.StringLng()); if (direction.Success) { plottedRoutes.Clear(); Map.Polylines.Clear(); ShowMeMyCameraUpdate(direction.Routes[0].Bounds); Leg[] legs = null; for (int index = 0; index < direction.Routes.Length; index++) { var route = direction.Routes[index]; legs = direction.Routes[0].Legs; Polyline polyLineData = new Polyline { StrokeWidth = 5, StrokeColor = Color.FromRgb(118, 170, 219) }; foreach (var coord in route.OverviewPolylineCoords) { polyLineData.Positions.Add(new Position(coord.Lat, coord.Lng)); } Map.Polylines.Add(polyLineData); plottedRoutes.Add(polyLineData); } //FOR DISTANCE ServiceInfo(legs[0]); } Device.BeginInvokeOnMainThread(() => IsBusyOnMap = false); //IsBusy = false; } ; }
private async void SetPinsOnMap(MapLongClickedEventArgs e) { if (Start == null) { Start = new Geocode(e.Point.Latitude, e.Point.Longitude); StartPin = CreatePin(e, Constants.ORIGEN_LABEL); Map.Pins.Add(StartPin); Origin = await googleMapsApi.GetAddress(Start.StringLat(), Start.StringLng()); SetOneDirection(); return; } if (End == null) { End = new Geocode(e.Point.Latitude, e.Point.Longitude); EndPin = CreatePin(e, Constants.DESTINO_LABEL); Map.Pins.Add(EndPin); Destination = await googleMapsApi.GetAddress(End.StringLat(), End.StringLng()); return; } }