Exemple #1
0
        void FnSetDirectionQuery(string strJSONDirectionResponse)
        {
            var objRoutes = JsonConvert.DeserializeObject <GoogleDirectionClass> (strJSONDirectionResponse);

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

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

                var polylineoption = new PolylineOptions();
                polylineoption.InvokeColor(Android.Graphics.Color.Green);
                polylineoption.Geodesic(true);
                polylineoption.Add(latLngPoints);
                RunOnUiThread(() =>
                              eMap.AddPolyline(polylineoption));
            }
        }
        private async void LoadMap(bool loadTripInfo)
        {
            mMap.Clear();

            RunOnUiThread(() =>
            {
                progress.Show();
            });

            LatLngBounds.Builder builder = new LatLngBounds.Builder();
            builder.Include(originLatLng);
            builder.Include(destLatLng);
            LatLngBounds bounds = builder.Build();

            int          padding = 100; // offset from edges of the map in pixels
            CameraUpdate cu      = CameraUpdateFactory.NewLatLngBounds(bounds, padding);

            // Add markers to oriign and destination
            mMap.AddMarker(new MarkerOptions().SetPosition(originLatLng).SetTitle("Origin"));
            mMap.AddMarker(new MarkerOptions().SetPosition(destLatLng).SetTitle("Destination"));

            // Combine Google Direction API string
            string urlGoogleDirection = MapHelper.GoogleDirectionAPIAddress(originLatLng.Latitude + "," + originLatLng.Longitude,
                                                                            destLatLng.Latitude + "," + destLatLng.Longitude);
            string strGoogleDirection = await MapHelper.DownloadStringAsync(urlGoogleDirection);

            var googleDirectionAPIRoute = JsonConvert.DeserializeObject <GoogleDirectionAPI>(strGoogleDirection);

            string encodedPoints    = googleDirectionAPIRoute.routes[0].overview_polyline.points;
            var    lstDecodedPoints = MapHelper.DecodePolylinePoint(encodedPoints);
            //convert list of location point to array of latlng type

            var latLngPoints   = lstDecodedPoints.ToArray();
            var polylineoption = new PolylineOptions();

            polylineoption.InvokeColor(Android.Graphics.Color.SkyBlue);
            polylineoption.Geodesic(true);
            polylineoption.Add(latLngPoints);
            mMap.AddPolyline(polylineoption);
            mMap.AnimateCamera(cu);

            if (loadTripInfo)
            {
                LoadTripInformation();
            }
            RunOnUiThread(() =>
            {
                progress.Dismiss();
            });
        }
Exemple #3
0
        public void drawPolyline(string encodedPolyline)
        {
            if (map != null)
            {
                mEncodedPolyline = encodedPolyline;
                decodedLatLngs   = getDecodedPolyline(encodedPolyline);

                var polylineoption = new PolylineOptions();
                polylineoption.InvokeColor(POLYLINE_COLOR);
                polylineoption.Geodesic(true);
                polylineoption.Add(decodedLatLngs);
                map.AddPolyline(polylineoption);
            }
        }
        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;
        }
        public void DrawRoute(GoogleMap g)
        {
            var lat1  = "42.02332";
            var long1 = "-93.66791";
            var lat2  = "42.020454";
            var long2 = "-93.60969";

            //below is the concatinated url to check outputs
            //url = https://maps.googleapis.com/maps/api/directions/json?origin=42.02332,-93.66791&destination=42.020454,-93.60969&key=AIzaSyAJ80rolI5NRBXgrvwylHrcAQBGhii_1dI
            var url = "https://maps.googleapis.com/maps/api/directions/json?" +
                      "origin=" + lat1 + "," + long1 +
                      "&destination=" + lat2 + "," + long2 +
                      "&key=" + "AIzaSyAJ80rolI5NRBXgrvwylHrcAQBGhii_1dI";

            var json = "";

            using (WebClient wc = new WebClient())
            {
                json = wc.DownloadString(url);
            }

            RootObject myr = JsonConvert.DeserializeObject <RootObject>(json);

            //DependencyService.Get<IMessage>().LongAlert("checking how many GWP in root:" + myr.Routes[0].Legs.Count);

            var latLngPoints = new LatLng[(myr.Routes[0].Legs[0].Steps.Count) * 2];
            int index        = 0;

            foreach (var step in myr.Routes[0].Legs[0].Steps)
            {
                var startingLat  = step.Start_location.Lat;
                var startingLong = step.Start_location.Lng;
                var endingLat    = step.End_location.Lat;
                var endingLong   = step.End_location.Lng;

                latLngPoints[index++] = new LatLng(startingLat, startingLong);
                latLngPoints[index++] = new LatLng(endingLat, endingLong);
            }

            var polylineoption = new PolylineOptions();

            polylineoption.InvokeColor(Android.Graphics.Color.DarkBlue);
            polylineoption.Geodesic(true);
            polylineoption.Add(latLngPoints);
            g.AddPolyline(polylineoption);
        }
        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;
        }
Exemple #7
0
        private void ShowOnMap()
        {
            var polylineoption = new PolylineOptions();

            polylineoption.InvokeColor(Color.ParseColor("#509BFC"));
            polylineoption.Geodesic(true);

            List <Position> route = CalculateRoute.GetPositions(Assets);

            foreach (var pos in route)
            {
                polylineoption.Add(new LatLng(pos.Latitude, pos.Longitude));
            }

            var    index   = Convert.ToInt32((route.IndexOf(route.FirstOrDefault()) + route.IndexOf(route.LastOrDefault())) / 2);
            LatLng lastpos = new LatLng(route[index].Latitude, route[index].Longitude);

            mMap.AddPolyline(polylineoption);

            UpdateCameraPosition(lastpos);
        }
        //This function initilize the Map
        public void fnInitiateMapAsync()
        {
            if (map != null)
            {
                ShowLoading();
                map.MapType = GoogleMap.MapTypeSatellite;                          //select the map type
                CameraPosition.Builder builder = CameraPosition.InvokeBuilder();
                builder.Target(new LatLng(position.Latitude, position.Longitude)); //Target to some location hardcoded
                builder.Zoom(18);                                                  //Zoom multiplier
                builder.Bearing(45);                                               //bearing is the compass measurement clockwise from North
                builder.Tilt(90);                                                  //tilt is the viewing angle from vertical
                CameraPosition cameraPosition = builder.Build();
                CameraUpdate   cameraUpdate   = CameraUpdateFactory.NewCameraPosition(cameraPosition);
                LatLng         latLng         = new LatLng(position.Latitude, position.Longitude);
                map.AnimateCamera(CameraUpdateFactory.NewLatLngZoom(latLng, 17));
                map.MyLocationEnabled = true;
                map.MapType           = GoogleMap.MapTypeNormal;

                Worker       pclClass = SharedObjects.pcl;
                List <Route> routes   = SharedObjects.routes;

                timeTxV.Text = "Temps: " + routes[0].legs[0].duration.text;

                string encodedPoints    = routes[0].overview_polyline.points;
                var    lstDecodedPoints = FnDecodePolylinePoints(encodedPoints);
                //convert list of location point to array of latlng type
                var latLngPoints = new LatLng[lstDecodedPoints.Count];
                int index        = 0;
                foreach (Position loc in lstDecodedPoints)
                {
                    latLngPoints[index++] = new LatLng(loc.Latitude, loc.Longitude);
                }
                var polylineoption = new PolylineOptions();
                polylineoption.InvokeColor(Android.Graphics.Color.Red);
                polylineoption.Geodesic(true);
                polylineoption.Add(latLngPoints);
                map.AddPolyline(polylineoption);
                DismissLoading();
            }
        }
        public static PolylineOptions ResolveRoute(GoogleDirection googleDirection)
        {
            PolylineOptions po = new PolylineOptions();

            if (googleDirection.routes.Count > 0)
            {
                string        encodedPoints = googleDirection.routes[0].overview_polyline.points;
                List <LatLng> decodedPoints = DecodePolyLinePoints(encodedPoints);

                LatLng[] latLngPoints = new LatLng[decodedPoints.Count];
                int      index        = 0;
                foreach (LatLng loc in decodedPoints)
                {
                    latLngPoints[index++] = loc;
                }

                po.InvokeColor(Android.Graphics.Color.Red);
                po.Geodesic(true);
                po.Add(latLngPoints);
            }

            return(po);
        }
Exemple #10
0
        public async void OnMapReady(GoogleMap googleMap)
        {
            mMap = googleMap;
            mMap.MyLocationEnabled = true;
            string strGoogleDirection;

            if (iTripDetail.Member.type.Equals("Driver"))
            {
                strGoogleDirection = await MapHelper.DownloadStringAsync(iTripDetail);
            }
            else
            {
                strGoogleDirection = await MapHelper.DownloadStringAsync(iTripDetail, "Passenger");

                button.Text    = "Driver Arrive";
                button.Enabled = true;
                button.Click  += PickupByDriver;
            }

            var    googleDirectionAPIRoute = JsonConvert.DeserializeObject <GoogleDirectionAPI>(strGoogleDirection);
            string ePoints        = googleDirectionAPIRoute.routes[0].overview_polyline.points;
            var    dPoints        = MapHelper.DecodePolylinePoint(ePoints);
            var    latLngPoints   = dPoints.ToArray();
            var    polylineoption = new PolylineOptions();

            polylineoption.InvokeColor(Android.Graphics.Color.SkyBlue);
            polylineoption.Geodesic(true);
            polylineoption.Add(latLngPoints);
            mMap.AddPolyline(polylineoption);
            DrawMarkers(iTripDetail);
            PopulateGeofenceList();
            CreateGeofences();
            RunOnUiThread(() =>
            {
                progress.Dismiss();
            });
        }
Exemple #11
0
        void FnSetDirectionQuery(GoogleDirectionClass objRoutes)
        {
            //objRoutes.routes.Count  --may be more then one
            if (objRoutes.routes.Count > 0)
            {
                string encodedPoints = objRoutes.routes[0].overview_polyline.points;

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

                var polylineoption = new PolylineOptions();
                polylineoption.InvokeColor(Android.Graphics.Color.Red);
                polylineoption.Geodesic(true);
                polylineoption.Add(latLngPoints);
                RunOnUiThread(() =>
                              map.AddPolyline(polylineoption));
            }
        }
Exemple #12
0
        public void OnMapReady(GoogleMap googleMap)
        {
            try
            {
                this.GMap = googleMap;

                LatLng          location    = new LatLng(StaticOrder.way_points[0].lat, StaticOrder.way_points[0].lng);
                PolylineOptions rectOptions = new PolylineOptions()
                {
                };
                rectOptions.Geodesic(true);
                rectOptions.InvokeWidth(1);
                rectOptions.InvokeColor(Color.Blue);

                for (int i = 0; i < StaticOrder.way_points.Count; i++)
                {
                    var latitude  = StaticOrder.way_points[i].lat;
                    var longitude = StaticOrder.way_points[i].lng;

                    LatLng new_location = new LatLng(
                        latitude,
                        longitude);

                    rectOptions.Add(new_location);

                    if (i == 0)
                    {
                        MarkerOptions markerOpt1 = new MarkerOptions();
                        //location = new LatLng(latitude, longitude);

                        markerOpt1.SetPosition(new LatLng(latitude, longitude));
                        markerOpt1.SetTitle("Пункт отправления\n" + StaticOrder.Inception_address);
                        //markerOpt1.SetSnippet(StaticOrder.Inception_address);

                        var bmDescriptor = BitmapDescriptorFactory.DefaultMarker(BitmapDescriptorFactory.HueBlue);
                        markerOpt1.InvokeIcon(bmDescriptor);

                        googleMap.AddMarker(markerOpt1);

                        continue;
                    }
                    else if (i == 1)
                    {
                        MarkerOptions markerOpt1 = new MarkerOptions();
                        //location = new LatLng(latitude, longitude);

                        markerOpt1.SetPosition(new LatLng(latitude, longitude));
                        markerOpt1.SetTitle("Пункт назначения\n" + StaticOrder.Destination_address);
                        //markerOpt1.SetSnippet(StaticOrder.Destination_address);

                        var bmDescriptor = BitmapDescriptorFactory.DefaultMarker(BitmapDescriptorFactory.HueRed);
                        markerOpt1.InvokeIcon(bmDescriptor);

                        googleMap.AddMarker(markerOpt1);

                        continue;
                    }
                    MarkerOptions markerOptions = new MarkerOptions();

                    markerOptions.SetPosition(new_location);
                    markerOptions.SetTitle(i.ToString());
                    googleMap.AddMarker(markerOptions);
                }

                googleMap.AddPolyline(rectOptions);

                CameraPosition.Builder builder = CameraPosition.InvokeBuilder();
                builder.Target(location);
                builder.Zoom(10);
                builder.Bearing(0);
                builder.Tilt(65);

                CameraPosition cameraPosition = builder.Build();
                CameraUpdate   cameraUpdate   = CameraUpdateFactory.NewCameraPosition(cameraPosition);

                //googleMap.UiSettings.ZoomControlsEnabled = true;
                //googleMap.UiSettings.CompassEnabled = true;
                googleMap.MoveCamera(cameraUpdate);
            }
            catch (Exception ex)
            {
                Toast.MakeText(Activity, ex.Message, ToastLength.Long).Show();
            }
        }
        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));
        }
Exemple #14
0
        public async void OnMapReady(GoogleMap googleMap)
        {
            mMap = googleMap;

            LatLngBounds.Builder builder = new LatLngBounds.Builder();
            builder.Include(originLatLng);
            builder.Include(destLatLng);
            LatLngBounds bounds = builder.Build();

            int          padding = 100; // offset from edges of the map in pixels
            CameraUpdate cu      = CameraUpdateFactory.NewLatLngBounds(bounds, padding);

            // Add markers to oriign and destination
            mMap.AddMarker(new MarkerOptions().SetPosition(originLatLng).SetTitle("Origin"));
            mMap.AddMarker(new MarkerOptions().SetPosition(destLatLng).SetTitle("Destination"));

            // Combine Google Direction API string
            string urlGoogleDirection = MapHelper.GoogleDirectionAPIAddress(iTrip.originLatLng, iTrip.destinationLatLng);
            string strGoogleDirection = await MapHelper.DownloadStringAsync(urlGoogleDirection);

            var    googleDirectionAPIRoute = JsonConvert.DeserializeObject <GoogleDirectionAPI>(strGoogleDirection);
            string encodedPoints           = googleDirectionAPIRoute.routes[0].overview_polyline.points;
            var    lstDecodedPoints        = MapHelper.DecodePolylinePoint(encodedPoints);
            //convert list of location point to array of latlng type

            var latLngPoints   = lstDecodedPoints.ToArray();
            var polylineoption = new PolylineOptions();

            polylineoption.InvokeColor(Android.Graphics.Color.SkyBlue);
            polylineoption.Geodesic(true);
            polylineoption.Add(latLngPoints);
            mMap.AddPolyline(polylineoption);
            mMap.AnimateCamera(cu);

            // Call google matrix api
            string urlGoogleMatrix = MapHelper.GoogleDistanceMatrixAPIAddress(iTrip.originLatLng, iTrip.destinationLatLng);
            string strGoogleMatrix = await MapHelper.DownloadStringAsync(urlGoogleMatrix);

            var googleDirectionMatrix = JsonConvert.DeserializeObject <GoogleDistanceMatrixAPI>(strGoogleMatrix);

            txtviewDistance.Text = googleDirectionMatrix.rows[0].elements[0].distance.text.ToString();
            txtviewDuration.Text = googleDirectionMatrix.rows[0].elements[0].duration.text.ToString();
            distanceValue        = double.Parse(googleDirectionMatrix.rows[0].elements[0].distance.value.ToString());
            durationValue        = int.Parse(googleDirectionMatrix.rows[0].elements[0].duration.value.ToString());

            double cost;

            if (iMember.type.Equals("Driver"))
            {
                cost = Math.Round(dblDriverCostKM * googleDirectionMatrix.rows[0].elements[0].distance.value, 2);
            }
            else
            {
                cost = Math.Round(dblPassengerCostKM * googleDirectionMatrix.rows[0].elements[0].distance.value, 2);
            }
            txtviewCost.Text = string.Format("RM{0:0.00}", cost);

            RunOnUiThread(() =>
            {
                progress.Dismiss();
            });
        }
Exemple #15
0
        public void OnMapReady(GoogleMap googleMap)
        {
            this.GMap = googleMap;

            LatLng          location    = new LatLng(StaticTask.way_points[0].lat, StaticTask.way_points[0].lng);
            PolylineOptions rectOptions = new PolylineOptions()
            {
            };

            rectOptions.Geodesic(true);
            rectOptions.InvokeWidth(1);
            rectOptions.InvokeColor(Color.Blue);

            for (int i = 0; i < StaticTask.way_points.Count; i++)
            {
                var latitude  = StaticTask.way_points[i].lat;
                var longitude = StaticTask.way_points[i].lng;

                LatLng new_location = new LatLng(
                    latitude,
                    longitude);

                rectOptions.Add(new_location);

                if (i == 0)
                {
                    MarkerOptions markerOpt1 = new MarkerOptions();
                    //location = new LatLng(latitude, longitude);

                    markerOpt1.SetPosition(new LatLng(latitude, longitude));
                    markerOpt1.SetTitle("Start");
                    markerOpt1.SetSnippet("Текущее положение");

                    var bmDescriptor = BitmapDescriptorFactory.DefaultMarker(BitmapDescriptorFactory.HueBlue);
                    markerOpt1.InvokeIcon(bmDescriptor);

                    googleMap.AddMarker(markerOpt1);

                    continue;
                }
                MarkerOptions markerOptions = new MarkerOptions();

                markerOptions.SetPosition(new_location);
                markerOptions.SetTitle(i.ToString());
                googleMap.AddMarker(markerOptions);
                mMapView.OnResume();
            }

            googleMap.AddPolyline(rectOptions);

            CameraPosition.Builder builder = CameraPosition.InvokeBuilder();
            builder.Target(location);
            builder.Zoom(10);
            builder.Bearing(0);
            builder.Tilt(65);

            CameraPosition cameraPosition = builder.Build();
            CameraUpdate   cameraUpdate   = CameraUpdateFactory.NewCameraPosition(cameraPosition);

            googleMap.UiSettings.CompassEnabled = true;
            //googleMap.UiSettings.IndoorLevelPickerEnabled = true;
            //googleMap.UiSettings.MapToolbarEnabled = true;
            //googleMap.UiSettings.RotateGesturesEnabled = true;
            //googleMap.UiSettings.ScrollGesturesEnabledDuringRotateOrZoom = true;
            googleMap.MoveCamera(cameraUpdate);
        }
Exemple #16
0
        protected override void OnCreate(Bundle bundle)
        {
            base.OnCreate(bundle);

            // Set our view from the "main" layout resource
            SetContentView(Resource.Layout.Main);
            Inicializa_MapFragment();
            //Definimos las ciudades en las cuales pondremos nuestros marcadores en el mapa
            MisCiudades.Add(new Ciudad_Marca("MÉXICO D.F.", "En su forma abreviada México, D. F., es la capital y sede de los poderes federales de los Estados Unidos Mexicanos.", new LatLng(19.430334, -99.13599), "p1"));
            MisCiudades.Add(new Ciudad_Marca("LEÓN", "Es una ciudad mexicana localizada  en el Estado de Guanajuato,México, en la región del Bajío.", new LatLng(21.12806, -101.689163), "p2"));
            MisCiudades.Add(new Ciudad_Marca("LAGOS DE MORENO", " Es un municipio y la ciudad más grande y poblada de la Región denominada Los Altos de Jalisco, ubicados en el estado mexicano de Jalisco.", new LatLng(21.36453, -101.939076), "p3"));
            MisCiudades.Add(new Ciudad_Marca("GUADALAJARA", "es una ciudad mexicana, capital del estado de Jalisco, así como principal localidad del área urbana denominada Zona Metropolitana de Guadalajara.", new LatLng(20.663626, -103.343754), "p4"));

            CargamosMarcadores();

            Button btnLinea    = FindViewById <Button> (Resource.Id.btnLinea);
            Button btnCirculo  = FindViewById <Button> (Resource.Id.btnCirculo);
            Button btnPoligono = FindViewById <Button> (Resource.Id.btnPoligono);

            txtPosicion = (TextView)FindViewById(Resource.Id.txtPosicion);



            btnLinea.Click += delegate {
                PolylineOptions rectOptions = new PolylineOptions();
                if (mMap != null)
                {
                    foreach (Ciudad_Marca ciudad in MisCiudades)
                    {
                        rectOptions.Add(ciudad.Ubicacion);
                    }

                    rectOptions.InvokeColor(Color.Red.ToArgb());
                    rectOptions.InvokeWidth(25);
                    rectOptions.Geodesic(true);

                    mMap.AddPolyline(rectOptions);
                }
            };

            btnCirculo.Click += delegate {
                if (mMap != null)
                {
                    foreach (Ciudad_Marca ciudad in MisCiudades)
                    {
                        CircleOptions circleOptions = new CircleOptions();
                        circleOptions.InvokeCenter(ciudad.Ubicacion);
                        circleOptions.InvokeRadius(10000);

                        circleOptions.InvokeStrokeWidth(10);
                        circleOptions.InvokeStrokeColor(Color.Blue.ToArgb());

                        Color micolorfill = Color.FromArgb(150, 149, 153, 225);
                        circleOptions.InvokeFillColor(micolorfill.ToArgb());

                        mMap.AddCircle(circleOptions);
                    }
                }
            };

            btnPoligono.Click += delegate {
                if (mMap != null)
                {
                    PolygonOptions Poligono = new PolygonOptions();
                    foreach (Ciudad_Marca ciudad in MisCiudades)
                    {
                        Poligono.Add(ciudad.Ubicacion);
                    }

                    Poligono.InvokeStrokeWidth(10);
                    Poligono.InvokeStrokeColor(Color.Green.ToArgb());

                    Color micolorfill = Color.FromArgb(150, 0, 255, 51);
                    Poligono.InvokeFillColor(micolorfill.ToArgb());

                    mMap.AddPolygon(Poligono);
                }
            };
        }