示例#1
0
        private void CheckIfSrcDestSatisfied(SharedPartnerDataModels.PlacesBounds sourceDestinationInfo)
        {
            if ((sourceDestinationInfo.pickUp.Id != string.Empty) && (sourceDestinationInfo.destination.Id != string.Empty))
            {
                SharedPartnerDataModels.Bounds2 bounds2 = new SharedPartnerDataModels.Bounds2();
                bounds2.northeastLocationName = sourceDestinationInfo.pickUp.Address;
                bounds2.northeast.lat         = sourceDestinationInfo.pickUp.LatLng.lat;
                bounds2.northeast.lng         = sourceDestinationInfo.pickUp.LatLng.lng;

                bounds2.southwestLocationName = sourceDestinationInfo.destination.Address;
                bounds2.southwest.lat         = sourceDestinationInfo.destination.LatLng.lat;
                bounds2.southwest.lng         = sourceDestinationInfo.destination.LatLng.lng;

                if (sourceDestinationInfo.pickUp.State == sourceDestinationInfo.destination.State)
                {
                    Logger.Log("METROPOLITAN TRIP", "TRIP DETECTION");
                }
                else
                {
                    Logger.Log("INTER STATE   TRIP", "TRIP DETECTION");
                }
                FnGetDirectionsData(bounds2);
                // await Task.Run(() => FnGetDirectionsData(bounds2));
            }
        }
示例#2
0
        void FnGetDirectionsData(SharedPartnerDataModels.Bounds2 bounds)
        {
            SharedPartnerDataModels.GoogleDirectionClass directions = new UiServices().GetDirectionsData(bounds);

            if (directions == null)
            {
                return;
            }
            //objRoutes.routes.Count  --may be more then one
            if (directions.routes.Count > 0)
            {
                string encodedPoints = directions.routes[0].overview_polyline.points;

                List <SharedPartnerDataModels.Location> lstDecodedPoints = new List <SharedPartnerDataModels.Location>();
                try
                {
                    lstDecodedPoints = UiServices.FnDecodePolylinePoints(encodedPoints);
                    //lstDecodedPoints = UiServices.locDecodePoly (encodedPoints);

                    //convert list of location point to array of latlng type
                    var latLngPoints = new LatLng[lstDecodedPoints.Count];
                    int index        = 0;
                    foreach (SharedPartnerDataModels.Location loc in lstDecodedPoints)
                    {
                        latLngPoints[index++] = new LatLng(loc.lat, loc.lng);
                    }

                    //Draw Polylines on Map
                    PolylineOptions polylineOptions = new PolylineOptions().Add(latLngPoints).InvokeWidth(10).InvokeColor(Color.Teal)
                                                      .InvokeStartCap(new SquareCap()).InvokeEndCap(new SquareCap()).InvokeJointType(JointType.Round).Geodesic(true);

                    if (mMap != null)
                    {
                        mMap.Clear();
                        RunOnUiThread(() => mMap.AddPolyline(polylineOptions));

                        string snippet = "Duration :" + directions.routes.FirstOrDefault().legs.FirstOrDefault().duration.text;
                        snippet += "\n Distance :" + directions.routes.FirstOrDefault().legs.FirstOrDefault().distance.text;

                        RunOnUiThread(() =>
                        {
                            new MarkLocationOnMap(mMap, bounds.northeastLocationName, new LatLng(bounds.northeast.lat, bounds.northeast.lng));                                                                                 // Resource.Drawable.MarkerSource);
                            new MarkLocationOnMap(mMap, bounds.southwestLocationName, snippet, new LatLng(bounds.southwest.lat, bounds.southwest.lng), BitmapDescriptorFactory.DefaultMarker(BitmapDescriptorFactory.HueRed)); // Resource.Drawable.MarkerDest);
                        });

                        PickUpRadio.Checked      = false;
                        DestinationRadio.Checked = false;

                        //Get Trip Bounds
                        //LatLng southwest = new LatLng(bounds.southwest.lng, bounds.southwest.lng);
                        //LatLng northeast = new LatLng(bounds.northeast.lng, bounds.northeast.lng);
                        //LatLngBounds tripBound = new LatLngBounds(southwest, northeast);

                        //mMap.AnimateCamera(CameraUpdateFactory.NewLatLngBounds(tripBound, 100));
                        //mMap.SetPadding(40, 40, 40, 40);
                    }
                    //var polylineOptions = new PolylineOptions().Visible(true).InvokeColor(Android.Graphics.Color.Red).Geodesic(true);
                    //polylineoption.InvokeWidth(5).InvokeZIndex(30).Add(latLngPoints);
                }
                catch (Exception ex)
                {
                    Logger.Log(ex.StackTrace, ex.Message);

                    RunOnUiThread(() =>
                                  Toast.MakeText(this, "Please Wait....", ToastLength.Short).Show());
                }
            }
        }