//Implements the IOnMapReadyCallback interface
        public void OnMapReady(MapboxMap map)
        {
            mapboxMap = map;

            // This will refer to OnStyleLoaded
            map.SetStyle(Style.MapboxStreets, this);
            var title1 = "Chicago";
            var lat1   = 41.897627;
            var lng1   = -87.643526;
            var title2 = "St.Louis";
            var lat2   = 38.742291;
            var lng2   = -90.064928;

            pickupPoint   = new LatLng(lat1, lng1);
            delivertPoint = new LatLng(lat2, lng2);

            bool crossesMeridianOrDateline;

            if ((lng1 > 0.0 && lng2 < 0.0) || (lng1 < 0.0 && lng2 > 0.0))
            {
                crossesMeridianOrDateline = true;
            }
            else
            {
                crossesMeridianOrDateline = false;
            }

            var xDiffPrimeMeridianZero = FindXDiffPrimeMeridianZero(lng1, lng2);
            var xDiffDatelineZero      = FindXDiffDatelineZero(lng1, lng2);

            List <double> xList;
            List <double> lngList;

            if ((Math.Abs(xDiffDatelineZero) > Math.Abs(xDiffPrimeMeridianZero)) && crossesMeridianOrDateline == true)
            {
                var latCenter = (lat1 + lat2) / 2.0;

                // Find center coordinate here
                var    x1      = FindXPrimeMeridianZero(lng1);
                var    xCenter = x1 + (xDiffPrimeMeridianZero / 2.0);
                double lngCenter;

                if (x1 > 180.0)
                {
                    lngCenter = xCenter - 360.0;
                }
                else
                {
                    lngCenter = xCenter;
                }

                var cameraCenter = new CameraPosition.Builder().Target(new LatLng(latCenter, lngCenter)).Zoom(1.5).Build();

                map.AnimateCamera(CameraUpdateFactory.NewCameraPosition(cameraCenter));

                xList   = CreateXList(xDiffPrimeMeridianZero, x1);
                lngList = ConvertToLngsPrimeMeridianZero(xList);
            }
            else
            {
                // find max/min lat/lng here
                // use those to determine the initialBounds

                var latDict = FindLowHigh(lat1, lat2);
                var latHigh = latDict["high"];
                var latLow  = latDict["low"];
                var lngDict = FindLowHigh(lng1, lng2);
                var lngHigh = lngDict["high"];
                var lngLow  = lngDict["low"];

                var latBuffer = (latHigh - latLow) / 4.0;
                var lngBuffer = (lngHigh - lngLow) / 10.0;

                var swLat = latLow - latBuffer;
                var swLng = lngLow - lngBuffer;
                var neLat = latHigh + latBuffer;
                var neLng = lngHigh + lngBuffer;

                var swPoint = new LatLng(swLat, swLng);
                var nePoint = new LatLng(neLat, neLng);

                var latLngBounds = new LatLngBounds.Builder()
                                   .Include(nePoint) // Northeast
                                   .Include(swPoint) // Southwest
                                   .Build();

                mapboxMap.EaseCamera(CameraUpdateFactory.NewLatLngBounds(latLngBounds, 0));

                xList   = CreateXList(xDiffDatelineZero, FindXDatelineZero(lng1));
                lngList = ConvertToLngsDatelineZero(xList);
            }

            var yList = CreateYList(lat1, lat2);

            var latList = ConvertToLats(yList);
            var coords  = ConvertToCoords(latList, lngList);

            CreateDashedLine(coords);

            var marker1 = new MarkerOptions();
            var marker2 = new MarkerOptions();

            marker1.SetPosition(pickupPoint);
            marker1.SetTitle(title1);
            marker2.SetPosition(delivertPoint);
            marker2.SetTitle(title2);
            map.AddMarker(marker1);
            map.AddMarker(marker2);
        }
Exemplo n.º 2
0
        public void DrawPolylineOnMap(string json, GoogleMap mainMap)
        {
            Android.Gms.Maps.Model.Polyline mPolyLine;

            var directionData = JsonConvert.DeserializeObject <DirectionParser>(json);

            string durationString = directionData.routes[0].legs[0].duration.text;
            string distanceString = directionData.routes[0].legs[0].distance.text;

            var polylineCode = directionData.routes[0].overview_polyline.points;
            var line         = PolyUtil.Decode(polylineCode);

            LatLng    firstpoint = line[0];
            LatLng    lastpoint  = line[line.Count - 1];
            ArrayList routeList  = new ArrayList();

            int locationCount = 0;

            foreach (LatLng item in line)
            {
                routeList.Add(item);
                locationCount++;

                Console.WriteLine("Poistion " + locationCount.ToString() + " = " + item.Latitude + "," + item.Longitude.ToString());
            }

            PolylineOptions polylineOptions = new PolylineOptions()
                                              .AddAll(routeList)
                                              .InvokeWidth(10)
                                              .InvokeColor(Color.Teal)
                                              .Geodesic(true)
                                              .InvokeJointType(JointType.Round);

            mPolyLine = mainMap.AddPolyline(polylineOptions);

            // Location Marker
            MarkerOptions locationMarkerOption = new MarkerOptions();

            locationMarkerOption.SetPosition(firstpoint);
            locationMarkerOption.SetTitle("My Location");
            locationMarkerOption.SetIcon(BitmapDescriptorFactory.DefaultMarker(BitmapDescriptorFactory.HueGreen));
            Marker locationmarker = mainMap.AddMarker(locationMarkerOption);

            // Destination Marker
            MarkerOptions destinationMarkerOption = new MarkerOptions();

            destinationMarkerOption.SetPosition(lastpoint);
            destinationMarkerOption.SetTitle("Destination");
            destinationMarkerOption.SetSnippet(durationString + ", " + distanceString);
            destinationMarkerOption.SetIcon(BitmapDescriptorFactory.DefaultMarker(BitmapDescriptorFactory.HueRed));
            Marker destinationMarker = mainMap.AddMarker(destinationMarkerOption);

            // Current Location Marker
            MarkerOptions positionMakerOption = new MarkerOptions();

            positionMakerOption.SetPosition(firstpoint);
            positionMakerOption.SetTitle("Current Location");
            positionMakerOption.SetIcon(BitmapDescriptorFactory.FromResource(Resource.Drawable.positionmarker));
            positionMakerOption.Visible(false);
            currentPositionMarker = mainMap.AddMarker(positionMakerOption);

            // Location Circle
            CircleOptions locationCircleOption = new CircleOptions();

            locationCircleOption.InvokeCenter(firstpoint);
            locationCircleOption.InvokeRadius(30);
            locationCircleOption.InvokeStrokeColor(Color.Teal);
            locationCircleOption.InvokeFillColor(Color.Teal);
            mainMap.AddCircle(locationCircleOption);

            // Destination Circle
            CircleOptions destiationCircleOption = new CircleOptions();

            destiationCircleOption.InvokeCenter(lastpoint);
            destiationCircleOption.InvokeRadius(30);
            destiationCircleOption.InvokeStrokeColor(Color.Teal);
            destiationCircleOption.InvokeFillColor(Color.Teal);
            mainMap.AddCircle(destiationCircleOption);

            LatLng southwest = new LatLng(directionData.routes[0].bounds.southwest.lat, directionData.routes[0].bounds.southwest.lng);
            LatLng northeast = new LatLng(directionData.routes[0].bounds.northeast.lat, directionData.routes[0].bounds.northeast.lng);

            LatLngBounds tripBounds = new LatLngBounds(southwest, northeast);

            mainMap.AnimateCamera(CameraUpdateFactory.NewLatLngBounds(tripBounds, 150));
            mainMap.UiSettings.ZoomControlsEnabled = true;
            destinationMarker.ShowInfoWindow();
        }
Exemplo n.º 3
0
        public async void getCurrentLoc(GoogleMap googleMap)
        {
            Console.WriteLine("Test - CurrentLoc");
            try
            {
                var request  = new GeolocationRequest(GeolocationAccuracy.Best);
                var location = await Geolocation.GetLocationAsync(request);

                if (location != null)
                {
                    Console.WriteLine($"current Loc - Latitude: {location.Latitude}, Longitude: {location.Longitude}, Altitude: {location.Altitude}");
                    MarkerOptions curLoc = new MarkerOptions();
                    curLoc.SetPosition(new LatLng(location.Latitude, location.Longitude));


                    var address = await Geocoding.GetPlacemarksAsync(location.Latitude, location.Longitude);

                    var placemark      = address?.FirstOrDefault();
                    var geocodeAddress = "";
                    if (placemark != null)
                    {
                        geocodeAddress =
                            $"AdminArea:       {placemark.AdminArea}\n" +
                            $"CountryCode:     {placemark.CountryCode}\n" +
                            $"CountryName:     {placemark.CountryName}\n" +
                            $"FeatureName:     {placemark.FeatureName}\n" +
                            $"Locality:        {placemark.Locality}\n" +
                            $"PostalCode:      {placemark.PostalCode}\n" +
                            $"SubAdminArea:    {placemark.SubAdminArea}\n" +
                            $"SubLocality:     {placemark.SubLocality}\n" +
                            $"SubThoroughfare: {placemark.SubThoroughfare}\n" +
                            $"Thoroughfare:    {placemark.Thoroughfare}\n";
                    }


                    curLoc.SetTitle("You are here");// + geocodeAddress);
                    curLoc.SetIcon(BitmapDescriptorFactory.DefaultMarker(BitmapDescriptorFactory.HueAzure));

                    googleMap.AddMarker(curLoc);


                    CameraPosition.Builder builder = CameraPosition.InvokeBuilder();
                    builder.Target(new LatLng(location.Latitude, location.Longitude));
                    builder.Zoom(18);
                    builder.Bearing(155);
                    builder.Tilt(65);

                    CameraPosition cameraPosition = builder.Build();

                    CameraUpdate cameraUpdate = CameraUpdateFactory.NewCameraPosition(cameraPosition);

                    googleMap.MoveCamera(cameraUpdate);
                }
            }
            catch (FeatureNotSupportedException fnsEx)
            {
                // Handle not supported on device exception
                Toast.MakeText(Activity, "Feature Not Supported", ToastLength.Short);
            }
            catch (FeatureNotEnabledException fneEx)
            {
                // Handle not enabled on device exception
                Toast.MakeText(Activity, "Feature Not Enabled", ToastLength.Short);
            }
            catch (PermissionException pEx)
            {
                // Handle permission exception
                Toast.MakeText(Activity, "Needs more permission", ToastLength.Short);
            }
        }
Exemplo n.º 4
0
        public void DrawTripOnMap(string json)
        {
            var directionData = JsonConvert.DeserializeObject <DirectionParser>(json);

            //Decode Encoded Route
            var points = directionData.routes[0].overview_polyline.points;
            var line   = PolyUtil.Decode(points);

            ArrayList routeList = new ArrayList();

            foreach (LatLng item in line)
            {
                routeList.Add(item);
            }

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

            Android.Gms.Maps.Model.Polyline mPolyline = map.AddPolyline(polylineOptions);

            //Get first point and lastpoint
            LatLng firstpoint = line[0];
            LatLng lastpoint  = line[line.Count - 1];

            //Pickup marker options
            MarkerOptions pickupMarkerOptions = new MarkerOptions();

            pickupMarkerOptions.SetPosition(firstpoint);
            pickupMarkerOptions.SetTitle("Pickup Location");
            pickupMarkerOptions.SetIcon(BitmapDescriptorFactory.DefaultMarker(BitmapDescriptorFactory.HueGreen));

            //Destination marker options
            MarkerOptions destinationMarkerOptions = new MarkerOptions();

            destinationMarkerOptions.SetPosition(lastpoint);
            destinationMarkerOptions.SetTitle("Destination");
            destinationMarkerOptions.SetIcon(BitmapDescriptorFactory.DefaultMarker(BitmapDescriptorFactory.HueRed));


            MarkerOptions driverMarkerOptions = new MarkerOptions();

            driverMarkerOptions.SetPosition(firstpoint);
            driverMarkerOptions.SetTitle("Current Location");
            driverMarkerOptions.SetIcon(BitmapDescriptorFactory.FromResource(Resource.Drawable.position));
            driverMarkerOptions.Visible(false);


            pickupMarker = map.AddMarker(pickupMarkerOptions);
            Marker destinationMarker = map.AddMarker(destinationMarkerOptions);

            driverLocationMarker = map.AddMarker(driverMarkerOptions);

            //Get Trip Bounds
            double southlng = directionData.routes[0].bounds.southwest.lng;
            double southlat = directionData.routes[0].bounds.southwest.lat;
            double northlng = directionData.routes[0].bounds.northeast.lng;
            double northlat = directionData.routes[0].bounds.northeast.lat;

            LatLng       southwest = new LatLng(southlat, southlng);
            LatLng       northeast = new LatLng(northlat, northlng);
            LatLngBounds tripBound = new LatLngBounds(southwest, northeast);

            map.AnimateCamera(CameraUpdateFactory.NewLatLngBounds(tripBound, 100));
            map.SetPadding(40, 40, 40, 40);
            pickupMarker.ShowInfoWindow();

            duration       = directionData.routes[0].legs[0].duration.value;
            distance       = directionData.routes[0].legs[0].distance.value;
            durationstring = directionData.routes[0].legs[0].duration.text;
            distanceString = directionData.routes[0].legs[0].distance.text;
        }
Exemplo n.º 5
0
        public void OnMapReady(GoogleMap map)
        {
            _map = map;
            if (_map != null)
            {
                _map.UiSettings.ZoomControlsEnabled = true;
                _map.UiSettings.CompassEnabled      = true;
                _map.MoveCamera(cameraUpdate);

                //adding current_users_location_marker
                MarkerOptions current_users_location_marker = new MarkerOptions();
                if (ChangeDestination.changedDestinationIndicator == false)
                {
                    current_users_location_marker.SetPosition(new LatLng(Convert.ToDouble(lat_temp_NEW_start_activity, (CultureInfo.InvariantCulture)),
                                                                         Convert.ToDouble(lng_temp_NEW_start_activity, (CultureInfo.InvariantCulture))));
                    current_users_location_marker.SetTitle("Your current location");
                }
                else if (ChangeDestination.changedDestinationIndicator == true)
                {
                    current_users_location_marker.SetPosition(new LatLng(ChangeDestination.lat, ChangeDestination.lng));
                    current_users_location_marker.SetTitle("Your target location");
                }
                BitmapDescriptor image = BitmapDescriptorFactory.FromResource(Resource.Drawable.currentLocation);
                current_users_location_marker.SetIcon(image);

                if (Tours_detail.searchOrMovieAdapterIndicator == "MovieAdapter")
                {
                    if (MovieAdapter.moviesStatic != null)
                    {
                        foreach (var i in MovieAdapter.moviesStatic)
                        {
                            if (!String.IsNullOrWhiteSpace(i.lat) && !String.IsNullOrWhiteSpace(i.lng))
                            {
                                /*lat_tmp = i.lat;
                                *  lng_tmp = i.lng;*/
                                foreach (char c in i.lat)
                                {
                                    if (c == ',')
                                    {
                                        lat_tmp += ".";
                                    }
                                    else
                                    {
                                        lat_tmp += c;
                                    }
                                }
                                foreach (char c in i.lng)
                                {
                                    if (c == ',')
                                    {
                                        lng_tmp += ".";
                                    }
                                    else
                                    {
                                        lng_tmp += c;
                                    }
                                }

                                MarkerOptions place_of_interest_marker = new MarkerOptions();
                                place_of_interest_marker.SetPosition(new LatLng(Convert.ToDouble(lat_tmp, (CultureInfo.InvariantCulture)),
                                                                                Convert.ToDouble(lng_tmp, (CultureInfo.InvariantCulture))));
                                lat_tmp = "";
                                lng_tmp = "";

                                long_title_indicator = false;

                                //making title shorter
                                int    count_char_in_title = 0;
                                string short_title         = "";
                                foreach (char c in i.title)
                                {
                                    count_char_in_title++;
                                    short_title += c;
                                    if (count_char_in_title == 32)
                                    {
                                        long_title_indicator = true;
                                        break;
                                    }
                                }
                                //making title shorter ENDED

                                if (long_title_indicator == false)
                                {
                                    place_of_interest_marker.SetTitle(short_title + ". Price: " + i.price + "$");
                                }
                                else if (long_title_indicator == true)
                                {
                                    place_of_interest_marker.SetTitle(short_title + "... Price: " + i.price + "$");
                                }

                                _map.AddMarker(place_of_interest_marker);
                            }
                        }
                    }
                }
                else if (Tours_detail.searchOrMovieAdapterIndicator == "SearchAdapter")
                {
                    foreach (var i in SearchAdapter.experiencesStatic)
                    {
                        if (!String.IsNullOrWhiteSpace(i.lat) && !String.IsNullOrWhiteSpace(i.lng))
                        {
                            /*lat_tmp = i.lat;
                            *  lng_tmp = i.lng;*/
                            foreach (char c in i.lat)
                            {
                                if (c == ',')
                                {
                                    lat_tmp += ".";
                                }
                                else
                                {
                                    lat_tmp += c;
                                }
                            }
                            foreach (char c in i.lng)
                            {
                                if (c == ',')
                                {
                                    lng_tmp += ".";
                                }
                                else
                                {
                                    lng_tmp += c;
                                }
                            }

                            MarkerOptions place_of_interest_marker = new MarkerOptions();
                            place_of_interest_marker.SetPosition(new LatLng(Convert.ToDouble(lat_tmp, (CultureInfo.InvariantCulture)),
                                                                            Convert.ToDouble(lng_tmp, (CultureInfo.InvariantCulture))));
                            lat_tmp = "";
                            lng_tmp = "";

                            long_title_indicator = false;

                            //making title shorter
                            int    count_char_in_title = 0;
                            string short_title         = "";
                            foreach (char c in i.title)
                            {
                                count_char_in_title++;
                                short_title += c;
                                if (count_char_in_title == 32)
                                {
                                    long_title_indicator = true;
                                    break;
                                }
                            }
                            //making title shorter ENDED

                            if (long_title_indicator == false)
                            {
                                place_of_interest_marker.SetTitle(short_title + ". Price: " + i.price + "$");
                            }
                            else if (long_title_indicator == true)
                            {
                                place_of_interest_marker.SetTitle(short_title + "... Price: " + i.price + "$");
                            }

                            _map.AddMarker(place_of_interest_marker);
                        }
                    }

                    if (lat_search_target_users_position != 0 && lng_search_target_users_position != 0)
                    {
                        current_users_location_marker.SetPosition(new LatLng(lat_search_target_users_position, lng_search_target_users_position));
                        current_users_location_marker.SetTitle("Your target location");
                    }
                    else
                    {
                        string lat_replaced = NEWstartActivity.lat;
                        string lng_replaced = NEWstartActivity.lon;
                        if (lat_replaced.Contains(","))
                        {
                            lat_replaced = NEWstartActivity.lat.Replace(',', '.');
                        }
                        if (lng_replaced.Contains(","))
                        {
                            lng_replaced = NEWstartActivity.lon.Replace(',', '.');
                        }
                        current_users_location_marker.SetPosition(new LatLng(Convert.ToDouble(lat_replaced, (CultureInfo.InvariantCulture)),
                                                                             Convert.ToDouble(lng_replaced, (CultureInfo.InvariantCulture))));
                        current_users_location_marker.SetTitle("Your current location");
                    }
                }
                _map.AddMarker(current_users_location_marker);
                //adding placesOfInterestMarker from items of the recycler list ENDED

                //adding myExperiences markers to map
                foreach (var i in MyBookings.myExpListClassForRecycler)
                {
                    if (!String.IsNullOrWhiteSpace(i._lat) && !String.IsNullOrWhiteSpace(i._lng))
                    {
                        /*lat_tmp = i._lat;
                        *  lng_tmp = i._lng;*/
                        foreach (char c in i._lat)
                        {
                            if (c == ',')
                            {
                                lat_tmp += ".";
                            }
                            else
                            {
                                lat_tmp += c;
                            }
                        }
                        foreach (char c in i._lng)
                        {
                            if (c == ',')
                            {
                                lng_tmp += ".";
                            }
                            else
                            {
                                lng_tmp += c;
                            }
                        }

                        MarkerOptions my_experience_marker = new MarkerOptions();
                        my_experience_marker.SetPosition(new LatLng(Convert.ToDouble(lat_tmp, (CultureInfo.InvariantCulture)),
                                                                    Convert.ToDouble(lng_tmp, (CultureInfo.InvariantCulture))));
                        lat_tmp = "";
                        lng_tmp = "";

                        long_title_indicator = false;

                        //making title shorter
                        int    count_char_in_title = 0;
                        string short_title         = "";
                        foreach (char c in i._name)
                        {
                            count_char_in_title++;
                            short_title += c;
                            if (count_char_in_title == 32)
                            {
                                long_title_indicator = true;
                                break;
                            }
                        }
                        //making title shorter ENDED

                        if (long_title_indicator == false)
                        {
                            my_experience_marker.SetTitle(short_title + ". Price: " + i._price + "$");
                        }
                        else if (long_title_indicator == true)
                        {
                            my_experience_marker.SetTitle(short_title + "... Price: " + i._price + "$");
                        }


                        BitmapDescriptor my_experience_image = BitmapDescriptorFactory.FromResource(Resource.Drawable.myExpMarker);
                        my_experience_marker.SetIcon(my_experience_image);

                        _map.AddMarker(my_experience_marker);

                        _map.AddMarker(my_experience_marker);
                    }
                }
                //adding myExperiences markers to map ENDED

                //adding wishlist markers to map
                //declaring path for RETRIEVING DATA
                ORM.DBRepository dbr    = new ORM.DBRepository();
                string           dbPath = System.IO.Path.Combine(System.Environment.GetFolderPath(System.Environment.SpecialFolder.Personal), "ormdemo.db3");
                var db             = new SQLiteConnection(dbPath);
                var wishlist_table = db.Table <ORM.Wishlist>();
                //creating wishlist table
                dbr.CreateWishlistTable();
                foreach (var i in wishlist_table)
                {
                    if (!String.IsNullOrWhiteSpace(i.lat) && !String.IsNullOrWhiteSpace(i.lng))
                    {
                        /*lat_tmp = i.lat;
                        *  lng_tmp = i.lng;*/
                        foreach (char c in i.lat)
                        {
                            if (c == ',')
                            {
                                lat_tmp += ".";
                            }
                            else
                            {
                                lat_tmp += c;
                            }
                        }
                        foreach (char c in i.lng)
                        {
                            if (c == ',')
                            {
                                lng_tmp += ".";
                            }
                            else
                            {
                                lng_tmp += c;
                            }
                        }

                        MarkerOptions wishlist_item_marker = new MarkerOptions();
                        wishlist_item_marker.SetPosition(new LatLng(Convert.ToDouble(lat_tmp, (CultureInfo.InvariantCulture)),
                                                                    Convert.ToDouble(lng_tmp, (CultureInfo.InvariantCulture))));
                        lat_tmp = "";
                        lng_tmp = "";

                        long_title_indicator = false;

                        //making title shorter
                        int    count_char_in_title = 0;
                        string short_title         = "";
                        foreach (char c in i.name)
                        {
                            count_char_in_title++;
                            short_title += c;
                            if (count_char_in_title == 32)
                            {
                                long_title_indicator = true;
                                break;
                            }
                        }
                        //making title shorter ENDED

                        if (long_title_indicator == false)
                        {
                            wishlist_item_marker.SetTitle(short_title + ". Price: " + i.price + "$");
                        }
                        else if (long_title_indicator == true)
                        {
                            wishlist_item_marker.SetTitle(short_title + "... Price: " + i.price + "$");
                        }


                        BitmapDescriptor wishlist_image = BitmapDescriptorFactory.FromResource(Resource.Drawable.wishMarker);
                        wishlist_item_marker.SetIcon(wishlist_image);

                        _map.AddMarker(wishlist_item_marker);
                    }
                }
                //adding wishlist markers to map
            }
        }
Exemplo n.º 6
0
        // Draw polylines
        public void DrawTripOnMap(string json)
        {
            Android.Gms.Maps.Model.Polyline mPolyline;
            // Marker pickupMarker;

            var directionData = JsonConvert.DeserializeObject <DirectionParser>(json);

            // Pickup Position
            var    pointCode  = directionData.routes[0].overview_polyline.points;
            var    line       = PolyUtil.Decode(pointCode);
            LatLng firstpoint = line[0];
            LatLng lastpoint  = line[line.Count - 1];


            // Take off position - Driver's current position
            MarkerOptions markerOptions = new MarkerOptions();

            markerOptions.SetPosition(firstpoint);
            markerOptions.SetIcon(BitmapDescriptorFactory.DefaultMarker(BitmapDescriptorFactory.HueRed));
            pickupMarker = mainMap.AddMarker(markerOptions);


            // constantly change current location
            MarkerOptions positionMarkerOption = new MarkerOptions();

            positionMarkerOption.SetPosition(firstpoint);
            positionMarkerOption.SetTitle("Current Location");
            positionMarkerOption.SetIcon(BitmapDescriptorFactory.FromResource(Resource.Drawable.position));
            positionMarker = mainMap.AddMarker(positionMarkerOption);


            // pick up position
            MarkerOptions markerOptions1 = new MarkerOptions();

            markerOptions1.SetPosition(lastpoint);
            markerOptions1.SetTitle("Pickup Location");
            markerOptions1.SetIcon(BitmapDescriptorFactory.DefaultMarker(BitmapDescriptorFactory.HueGreen));
            destinationMarker = mainMap.AddMarker(markerOptions1);


            // Array List
            // From the current position to pick up location

            ArrayList routeList     = new ArrayList();
            int       locationCount = 0;

            foreach (LatLng item in line)
            {
                routeList.Add(item);
                locationCount++;
                Console.WriteLine("Position " + locationCount.ToString() + " = " + item.Latitude.ToString() + " , " + item.Longitude.ToString());
            }


            // Polylines in map
            // specifications of the polylines
            PolylineOptions polylineOptions = new PolylineOptions()
                                              .AddAll(routeList)
                                              .InvokeWidth(10)
                                              .InvokeColor(Color.Teal)
                                              .InvokeStartCap(new SquareCap())
                                              .InvokeEndCap(new SquareCap())
                                              .InvokeJointType(JointType.Round)
                                              .Geodesic(true);


            // draw the polyline
            mPolyline = mainMap.AddPolyline(polylineOptions);
            mainMap.UiSettings.ZoomControlsEnabled = true;
            mainMap.AnimateCamera(CameraUpdateFactory.NewLatLngZoom(firstpoint, 15));
            pickupMarker.ShowInfoWindow();
        }
        protected override void OnCreate(Bundle savedInstanceState)
        {
            // Getting current location
            fusedLocationProviderClient = LocationServices.GetFusedLocationProviderClient(this);

            Task.Run(GetLastLocationFromDevice);

            base.OnCreate(savedInstanceState);

            auth      = FirebaseAuth.GetInstance(MainActivity.app);
            mDatabase = FirebaseDatabase.Instance.Reference;

            tourneyID = Intent.GetStringExtra("tourneyID") ?? "None";

            SetContentView(Resource.Layout.AddLocation);

            // Adding location button
            Button currentLocationButton = FindViewById <Button>(Resource.Id.currentLocationButton);

            currentLocationButton.Click += (sender, e) =>
            {
                CameraPosition.Builder builder = CameraPosition.InvokeBuilder();
                builder.Target(coords);
                builder.Zoom(18);
                builder.Bearing(155);
                builder.Tilt(65);
                CameraPosition cameraPosition = builder.Build();
                CameraUpdate   cameraUpdate   = CameraUpdateFactory.NewCameraPosition(cameraPosition);
                if (_map != null)
                {
                    // Puttin a marker in this location for admin to move around
                    MarkerOptions tournamentLocationMarker = new MarkerOptions();
                    tournamentLocationMarker.SetPosition(coords);
                    tournamentLocationMarker.SetTitle("Tournament Location");
                    tournamentLocationMarker.SetIcon(BitmapDescriptorFactory.DefaultMarker(BitmapDescriptorFactory.HueCyan));
                    tournamentLocationMarker.Draggable(true);
                    _map.MarkerDragEnd += MapOnMarkerDragEnd;
                    _map.AddMarker(tournamentLocationMarker);

                    // Moving Camera
                    _map.AnimateCamera(CameraUpdateFactory.NewCameraPosition(cameraPosition));

                    // Setting current location as tournament location in case admin does not want to change
                    var coordinates = coords.Latitude + "," + coords.Longitude;
                    mDatabase.Child("tournaments").Child(tourneyID).Child("location").SetValueAsync(coordinates);

                    // Changing button text
                    currentLocationButton.Text = "Tournament Location";
                }
                else
                {
                    Toast.MakeText(ApplicationContext, "Wait for location to load..", ToastLength.Long);
                }
            };

            // Adding Save location button
            Button saveLocationButton = FindViewById <Button>(Resource.Id.saveLocationButton);

            saveLocationButton.Click += async(sender, e) =>
            {
                if (coords != null)
                {
                    await mDatabase.Child("tournaments").Child(tourneyID).Child("online").SetValueAsync("false");

                    // Going back to Tournament Main page
                    Intent addTournamentActivity = new Intent(Application.Context, typeof(AddTournamentActivity));
                    addTournamentActivity.PutExtra("tourneyID", tourneyID);
                    StartActivity(addTournamentActivity);
                    Finish();
                }
                else
                {
                    Toast.MakeText(ApplicationContext, "Load Current Location and move Marker First", ToastLength.Long);
                }
            };

            InitMapFragment();
        }
Exemplo n.º 8
0
        private void ShowOnMap(ProgressDialog progressDialog)
        {
            try
            {
                // Create a new _gcstuffs
                _gcstuffs = new GCStuffs();

                // We read configuration from exportdata
                bool          needtoconf = false;
                List <String> conf       = GCStuffs.LoadDataString();
                if ((conf != null) && (conf.Count >= 2))
                {
                    // We have a configuration on exportdata
                    // check if account is valid and populate cookiejar
                    if (_gcstuffs.CheckGCAccount(conf[0], conf[1], true, this))
                    {
                        // All right !
                    }
                    else
                    {
                        needtoconf = true;
                    }
                }
                else
                {
                    needtoconf = true;
                }

                // Do we need to configure ? no reason to be there in that case
                if (needtoconf)
                {
                    // Need to configure :-(
                    RunOnUiThread(() => Toast.MakeText(this, this.Resources.GetString(Resource.String.AccountConfigure), ToastLength.Short).Show());
                    GoodBye();
                }

                // we get information
                // Now iterate
                // dictionary with data
                Dictionary <String, List <GCNotification> > diconotifs = new Dictionary <string, List <GCNotification> >();
                int nb = 1;
                foreach (String id in _ids)
                {
                    // Is it canceled ?
                    if (_Canceled)
                    {
                        break; // Yes
                    }
                    // Update progress
                    progressDialog.Progress = nb;

                    // Get info
                    String         post_response = ""; // Not used here
                    GCNotification gcn           = _gcstuffs.GetNotificationData(id, ref post_response);
                    if (gcn != null)
                    {
                        // We stacks notifs with same coordinates
                        // key is lat+lon
                        String key = gcn.dlat.ToString() + gcn.dlon.ToString() + gcn.distance.ToString();
                        if (diconotifs.ContainsKey(key))
                        {
                            // update existing
                            diconotifs[key].Add(gcn);
                        }
                        else
                        {
                            // new one
                            diconotifs.Add(key, new List <GCNotification>(new GCNotification[] { gcn }));
                        }
                    }

                    nb++;
                }

                // Store all marker locations
                List <LatLng> markerslocations = new List <LatLng>();

                // iterate on notifications
                foreach (KeyValuePair <String, List <GCNotification> > pair in diconotifs)
                {
                    // We create the marker
                    // Get color
                    Color                 c    = Color.Pink;
                    float                 b    = BitmapDescriptorFactory.HueRose;
                    GCNotification        gcn  = pair.Value[0];
                    List <GCNotification> gcns = pair.Value;
                    if (pair.Value.Count == 1)
                    {
                        // get color of this single notif
                        gcn.GetIcon(ref b, ref c);
                    }

                    // Create marker
                    LatLng location = new LatLng(gcn.dlat, gcn.dlon);
                    // Not necessary since we do it for the circles right below
                    //markerslocations.Add(location);

                    // Create markeroptions
                    MarkerOptions mk = new MarkerOptions();
                    mk.SetPosition(location);

                    // And the icon color
                    mk.SetIcon(BitmapDescriptorFactory.DefaultMarker(b));

                    // And a title and snippet
                    String title   = "";
                    String snippet = "";

                    // Title and snippet depending on number of gnc
                    if (gcns.Count == 1)
                    {
                        // Single notification
                        title   = gcn.name + " (" + gcn.distance.ToString() + " Km)";
                        snippet = gcn.GetTypeKeyInEnglish();
                    }
                    else
                    {
                        // Merged markers
                        // Create tooltip (may be to long, anyway...)
                        // Everyone is colocated
                        // Try to regroup by gcn names
                        Dictionary <String, List <GCNotification> > dicoNameGCN = new Dictionary <String, List <GCNotification> >();
                        foreach (GCNotification gn in gcns)
                        {
                            // Regroup by name
                            if (dicoNameGCN.ContainsKey(gn.name))
                            {
                                dicoNameGCN[gn.name].Add(gn);
                            }
                            else
                            {
                                dicoNameGCN.Add(gn.name, new List <GCNotification>(new GCNotification[] { gn }));
                            }
                        }

                        // Now create the tip
                        String tip = "";
                        foreach (KeyValuePair <String, List <GCNotification> > pair2 in dicoNameGCN)
                        {
                            // this is the gcn name
                            tip += pair2.Key + "\n";

                            // Now list all type / kind of notification
                            foreach (GCNotification g in pair2.Value)
                            {
                                // Type (tradi, etc...)
                                tip += "    " + g.GetTypeKeyInEnglish();// + ": ";

                                // And now the kind of notif (publish, etc...)
                                // NO! THIS IS THE POST VALUE NOT READABLE

                                /*
                                 * foreach(String kn in g.data.Item3)
                                 * {
                                 *  tip += kn + " ";
                                 * }
                                 */
                                // new line
                                tip += "\n";
                            }
                        }

                        // Assign values
                        title   = Resources.GetString(Resource.String.MergedMarkers) + " (" + gcns[0].distance.ToString() + " Km)";
                        snippet = tip;
                    }

                    // Assign real values
                    mk.SetTitle(title);
                    mk.SetSnippet(snippet);

                    // Add marker
                    RunOnUiThread(() => _map.AddMarker(mk));

                    // We create the circle marker
                    CircleOptions circleOptions = new CircleOptions();
                    circleOptions.InvokeCenter(location);
                    circleOptions.InvokeRadius(gcn.distance * 1000);
                    circleOptions.InvokeFillColor(Color.Argb(60, c.R, c.G, c.B));
                    //circleOptions.InvokeStrokeColor(Color.Argb(60, c.R, c.G, c.B));
                    circleOptions.InvokeStrokeWidth(2.0f);

                    // And we update the markerslocations with the bounding box of the circle
                    BoundingBox bb = GCStuffs.GetBoundingBox(new MapPoint {
                        Latitude = location.Latitude, Longitude = location.Longitude
                    }, gcn.distance);
                    markerslocations.Add(new LatLng(bb.MinPoint.Latitude, bb.MinPoint.Longitude));
                    markerslocations.Add(new LatLng(bb.MaxPoint.Latitude, bb.MaxPoint.Longitude));

                    // Create on map
                    RunOnUiThread(() => _map.AddCircle(circleOptions).Visible = true);
                }

                // Zoom map to fit
                if (markerslocations.Count != 0)
                {
                    RunOnUiThread(() => FitAllMarkers(markerslocations));
                }

                // Kill progressdialog (we are in UI thread already, good)
                RunOnUiThread(() => progressDialog.Hide());

                // All right!
                if (_Canceled)
                {
                    RunOnUiThread(() => Toast.MakeText(this, this.Resources.GetString(Resource.String.Canceled), ToastLength.Short).Show());
                }
                else
                {
                    RunOnUiThread(() => Toast.MakeText(this, this.Resources.GetString(Resource.String.Success), ToastLength.Short).Show());
                }
            }
            catch (Exception)
            {
                // Kill progressdialog (we are in UI thread already, good)
                RunOnUiThread(() => progressDialog.Hide());

                // Crap
                RunOnUiThread(() => Toast.MakeText(this, this.Resources.GetString(Resource.String.Error), ToastLength.Short).Show());
            }
        }
Exemplo n.º 9
0
        public void OnMapReady(GoogleMap googleMap)
        {
            gmap = googleMap;
            googleMap.MapType = MapTypeHybrid;
            locationCenter    = false;

            if (Build.VERSION.SdkInt >= BuildVersionCodes.M)
            {
                ActivityCompat.RequestPermissions(this,
                                                  new string[] {
                    Android.Manifest.Permission.AccessCoarseLocation,
                    Android.Manifest.Permission.AccessFineLocation
                },
                                                  REQUEST_LOCATION_PERMISSION);
            }
            else
            {
                editor.PutBoolean("location_permission", true);
                editor.Apply();
                apiClient.Connect();


                //gmap.SetOnMyLocationChangeListener(this);
                gmap.MyLocationEnabled = true;
            }

            mOptions = new MarkerOptions();
            //mOptions.Anchor(0, 0);

            gmap.MarkerDragEnd   += Gmap_MarkerDragEnd;
            gmap.MarkerDragStart += Gmap_MarkerDragStart;


            mOptions.Draggable(true);

            //animate over mbs if we has no permission for location
            if (!prefs.GetBoolean("location_permission", false))
            {
                CameraUpdate cu = CameraUpdateFactory.NewLatLngZoom(new LatLng(-40.226091, 175.566035), 12);
                googleMap.AnimateCamera(cu);
            }


            if (Lat_Lng != null)
            {
                mOptions.SetPosition(Lat_Lng);
                mOptions.SetTitle("Placed Marker");
                googleMap.AddMarker(mOptions);
                CameraUpdate cu = CameraUpdateFactory.NewLatLngZoom(new LatLng(mOptions.Position.Latitude, mOptions.Position.Longitude), 17);
                googleMap.AnimateCamera(cu);
            }
            //default marker
            else
            {
                mOptions.SetPosition(new LatLng(-40.226091, 175.566035));
                mOptions.SetTitle("Placed Marker");
                googleMap.AddMarker(mOptions);
                CameraUpdate cu = CameraUpdateFactory.NewLatLngZoom(new LatLng(mOptions.Position.Latitude, mOptions.Position.Longitude), 17);
                googleMap.AnimateCamera(cu);
                Lat_Lng = new LatLng(mOptions.Position.Latitude, mOptions.Position.Longitude);
            }



            googleMap.MapClick += (s, e) =>
            {
                //pre emptively clear map
                googleMap.Clear();
                Lat_Lng = new LatLng(e.Point.Latitude, e.Point.Longitude);
                mOptions.SetPosition(Lat_Lng);
                mOptions.SetTitle("Placed Marker");
                googleMap.AddMarker(mOptions);

                System.Console.WriteLine($"marker placed: {Lat_Lng.Latitude},{Lat_Lng.Longitude}");
            };
        }
Exemplo n.º 10
0
        public void OnMapReady(GoogleMap googleMap)
        {
            try
            {
                Map = googleMap;

                var makerOptions = new MarkerOptions();
                makerOptions.SetPosition(new LatLng(Lat, Lng));
                makerOptions.SetTitle(GetText(Resource.String.Lbl_Location));

                Map.AddMarker(makerOptions);
                Map.MapType = GoogleMap.MapTypeNormal;

                if (AppSettings.SetTabDarkTheme)
                {
                    MapStyleOptions style = MapStyleOptions.LoadRawResourceStyle(this, Resource.Raw.map_dark);
                    Map.SetMapStyle(style);
                }

                //Optional
                googleMap.UiSettings.ZoomControlsEnabled = true;
                googleMap.UiSettings.CompassEnabled      = true;

                OnLocationChanged();

                googleMap.MoveCamera(CameraUpdateFactory.ZoomIn());

                LatLng location = new LatLng(Lat, Lng);

                CameraPosition.Builder builder = CameraPosition.InvokeBuilder();
                builder.Target(location);
                builder.Zoom(18);
                builder.Bearing(155);
                builder.Tilt(65);

                CameraPosition cameraPosition = builder.Build();

                CameraUpdate cameraUpdate = CameraUpdateFactory.NewCameraPosition(cameraPosition);
                googleMap.MoveCamera(cameraUpdate);

                googleMap.MapClick += async(sender, e) =>
                {
                    try
                    {
                        LatLng latLng      = e.Point;
                        var    tapTextView = "Tapped: Point=" + e.Point;
                        Console.WriteLine(tapTextView);

                        Lat = latLng.Latitude;
                        Lng = latLng.Longitude;

                        // Creating a marker
                        MarkerOptions markerOptions = new MarkerOptions();

                        // Setting the position for the marker
                        markerOptions.SetPosition(e.Point);

                        var addresses = await ReverseGeocodeCurrentLocation(latLng);

                        if (addresses != null)
                        {
                            DeviceAddress = addresses.GetAddressLine(0); // If any additional address line present than only, check with max available address lines by getMaxAddressLineIndex()
                            //string city = addresses.Locality;
                            //string state = addresses.AdminArea;
                            //string country = addresses.CountryName;
                            //string postalCode = addresses.PostalCode;
                            //string knownName = addresses.FeatureName; // Only if available else return NULL

                            // Setting the title for the marker.
                            // This will be displayed on taping the marker
                            markerOptions.SetTitle(DeviceAddress);
                        }

                        // Clears the previously touched position
                        googleMap.Clear();

                        // Animating to the touched position
                        googleMap.AnimateCamera(CameraUpdateFactory.NewLatLng(e.Point));

                        // Placing a marker on the touched position
                        googleMap.AddMarker(markerOptions);
                    }
                    catch (Exception exception)
                    {
                        Console.WriteLine(exception);
                    }
                };

                googleMap.MapLongClick += (sender, e) =>
                {
                    try
                    {
                        var tapTextView = "Long Pressed: Point=" + e.Point;
                        Console.WriteLine(tapTextView);
                    }
                    catch (Exception exception)
                    {
                        Console.WriteLine(exception);
                    }
                };

                googleMap.CameraChange += (sender, e) =>
                {
                    try
                    {
                        var cameraTextView = e.Position.ToString();
                        Console.WriteLine(cameraTextView);
                    }
                    catch (Exception exception)
                    {
                        Console.WriteLine(exception);
                    }
                };
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
            }
        }
Exemplo n.º 11
0
        private async void SearchViewOnQueryTextSubmit(object sender, SearchView.QueryTextSubmitEventArgs e)
        {
            try
            {
                SearchText = e.NewText;

                if (string.IsNullOrEmpty(SearchText) || string.IsNullOrWhiteSpace(SearchText))
                {
                    return;
                }

                SearchView.ClearFocus();

                //Show a progress
                RunOnUiThread(() => { AndHUD.Shared.Show(this, GetText(Resource.String.Lbl_Loading)); });

                var latLng = await GetLocationFromAddress(SearchText.Replace(" ", ""));

                if (latLng != null)
                {
                    RunOnUiThread(() => { AndHUD.Shared.Dismiss(this); });

                    DeviceAddress = SearchText;

                    Lat = latLng.Latitude;
                    Lng = latLng.Longitude;

                    // Creating a marker
                    MarkerOptions markerOptions = new MarkerOptions();

                    // Setting the position for the marker
                    markerOptions.SetPosition(latLng);

                    var addresses = await ReverseGeocodeCurrentLocation(latLng);

                    if (addresses != null)
                    {
                        DeviceAddress = addresses.GetAddressLine(0); // If any additional address line present than only, check with max available address lines by getMaxAddressLineIndex()
                        //string city = addresses.Locality;
                        //string state = addresses.AdminArea;
                        //string country = addresses.CountryName;
                        //string postalCode = addresses.PostalCode;
                        //string knownName = addresses.FeatureName; // Only if available else return NULL

                        // Setting the title for the marker.
                        // This will be displayed on taping the marker
                        markerOptions.SetTitle(DeviceAddress);
                    }

                    // Clears the previously touched position
                    Map.Clear();

                    // Animating to the touched position
                    Map.AnimateCamera(CameraUpdateFactory.NewLatLng(latLng));

                    // Placing a marker on the touched position
                    Map.AddMarker(markerOptions);

                    CameraPosition.Builder builder = CameraPosition.InvokeBuilder();
                    builder.Target(latLng);
                    builder.Zoom(18);
                    builder.Bearing(155);
                    builder.Tilt(65);

                    CameraPosition cameraPosition = builder.Build();

                    CameraUpdate cameraUpdate = CameraUpdateFactory.NewCameraPosition(cameraPosition);
                    Map.MoveCamera(cameraUpdate);
                }
                else
                {
                    RunOnUiThread(() => { AndHUD.Shared.Dismiss(this); });


                    //Error Message
                    Toast.MakeText(this, GetText(Resource.String.Lbl_Error_DisplayAddress), ToastLength.Short).Show();
                }
            }
            catch (Exception exception)
            {
                RunOnUiThread(() => { AndHUD.Shared.Dismiss(this); });
                Console.WriteLine(exception);
            }
        }
Exemplo n.º 12
0
        public void OnMapReady(GoogleMap googleMap)
        {
            // throw new NotImplementedException();
            mMap = googleMap;
            // googleMap.MyLocationEnabled = true;
            LatLng latlng  = new LatLng(46.770439, 23.591423);
            LatLng latlng2 = new LatLng(47, 23.591423);

            CameraUpdate cameraUpdate = CameraUpdateFactory.NewLatLngZoom(latlng, 10); //pune camera pe marker

            googleMap.MoveCamera(cameraUpdate);
            //we create an instance of Marker Options
            //MarkerOptions markerOptions = new MarkerOptions();
            //markerOptions.SetPosition(latlng);
            //markerOptions.SetTitle("My location");
            //markerOptions.SetSnippet("Cluj-Napoca");
            //markerOptions.Draggable(true); //pot misca marker-ul pe harta

            //add another marker


            //  How to design the marker - asa obtin un marcaj albastru
            //  var bmDescriptor = BitmapDescriptorFactory.DefaultMarker(BitmapDescriptorFactory.HueCyan);
            //  markerOptions.InvokeIcon(bmDescriptor);
            //Marker1
            // googleMap.AddMarker(markerOptions); //To add a marker

            foreach (Depozit d in mDepozit)
            {
                MarkerOptions markerOptions = new MarkerOptions();
                //  var random1 = new Random();
                //    var random2 = new Random();
                //    double randomnumber1 = random1.Next();
                //    double randomnumber2 = random2.Next();

                markerOptions.SetPosition(new LatLng(d.Latitudine, d.Longitudine));
                markerOptions.SetTitle(d.Name);
                googleMap.AddMarker(markerOptions); //To add a marker
            }



            ////Optional
            googleMap.UiSettings.ZoomControlsEnabled = true; // +/- zoom in, zoom out
            googleMap.UiSettings.CompassEnabled      = true; //display compass
            // googleMap.MoveCamera(CameraUpdateFactory.ZoomIn());  // afiseaza harta de mai aproape

            googleMap.MapType = GoogleMap.MapTypeHybrid; //satellite map

            googleMap.MyLocationEnabled = true;


            //Optional2

            //LatLng location = new LatLng(50.897778, 3.013333);

            //unghiul de la care putem vedea harta

            //CameraPosition.Builder builder = CameraPosition.InvokeBuilder();
            //builder.Target(new LatLng(16.03, 108));
            //builder.Zoom(18); //zoom level
            //builder.Bearing(155); // The bearing is the compass measurement clockwise from North
            //builder.Tilt(65); //The Tilt property controls the viewing angle and specifies an angle of 25 degrees from the vertical

            //CameraPosition cameraPosition = builder.Build();

            //CameraUpdate cameraUpdate = CameraUpdateFactory.NewCameraPosition(cameraPosition);

            //googleMap.MoveCamera(cameraUpdate);

            // Marker 2
            //googleMap.AddMarker(new MarkerOptions()
            //    .SetPosition(latlng2)
            //    .SetTitle("Marker 2")
            //    .SetIcon(BitmapDescriptorFactory.DefaultMarker(BitmapDescriptorFactory.HueBlue)));

            mMap.MarkerClick += MMap_MarkerClick;

            mMap.MarkerDragEnd += MMap_MarkerDragEnd;
            mMap.SetInfoWindowAdapter(this);
        }
Exemplo n.º 13
0
        public void DrawTripToDestination(string json)
        {
            Android.Gms.Maps.Model.Polyline mPolyline;
            Marker pickupMarker;

            var directionData = JsonConvert.DeserializeObject <DirectionParser>(json);

            var    pointCode  = directionData.routes[0].overview_polyline.points;
            var    line       = PolyUtil.Decode(pointCode);
            LatLng firstpoint = line[0];
            LatLng lastpoint  = line[line.Count - 1];

            //My take off position
            MarkerOptions markerOptions = new MarkerOptions();

            markerOptions.SetPosition(firstpoint);
            markerOptions.SetIcon(BitmapDescriptorFactory.DefaultMarker(BitmapDescriptorFactory.HueGreen));
            markerOptions.SetTitle("Pickup Location");
            pickupMarker = mainMap.AddMarker(markerOptions);

            //Constanly Changing Current Location;
            MarkerOptions positionMarkerOption = new MarkerOptions();

            positionMarkerOption.SetPosition(firstpoint);
            positionMarkerOption.SetTitle("Current Location");
            positionMarkerOption.SetIcon(BitmapDescriptorFactory.FromResource(Resource.Drawable.position));
            positionMarker = mainMap.AddMarker(positionMarkerOption);

            MarkerOptions markerOptions1 = new MarkerOptions();

            markerOptions1.SetPosition(lastpoint);
            markerOptions1.SetTitle("Destination");
            markerOptions1.SetIcon(BitmapDescriptorFactory.DefaultMarker(BitmapDescriptorFactory.HueRed));
            destinationMarker = mainMap.AddMarker(markerOptions1);

            ArrayList routeList     = new ArrayList();
            int       locationCount = 0;

            foreach (LatLng item in line)
            {
                routeList.Add(item);
                locationCount++;
                Console.WriteLine("Position " + locationCount.ToString() + " = " + item.Latitude.ToString() + " , " + item.Longitude.ToString());
            }

            PolylineOptions polylineOptions = new PolylineOptions()
                                              .AddAll(routeList)
                                              .InvokeWidth(20)
                                              .InvokeColor(Color.Teal)
                                              .InvokeStartCap(new SquareCap())
                                              .InvokeEndCap(new SquareCap())
                                              .InvokeJointType(JointType.Round)
                                              .Geodesic(true);

            mPolyline = mainMap.AddPolyline(polylineOptions);
            mainMap.UiSettings.ZoomControlsEnabled = true;
            mainMap.TrafficEnabled = true;

            LatLng southwest = new LatLng(directionData.routes[0].bounds.southwest.lat, directionData.routes[0].bounds.southwest.lng);
            LatLng northeast = new LatLng(directionData.routes[0].bounds.northeast.lat, directionData.routes[0].bounds.northeast.lng);

            LatLngBounds tripBounds = new LatLngBounds(southwest, northeast);

            mainMap.AnimateCamera(CameraUpdateFactory.NewLatLngBounds(tripBounds, 100));
            destinationMarker.ShowInfoWindow();
        }