Example #1
0
        private async void DrawRoute(RouteDirectionDto routeDirectionDto)
        {
            map.Pins.Clear();
            map.MapElements.Clear();

            var steps = ProcessRouteResult(routeDirectionDto);

            Xamarin.Forms.Maps.Polyline polyline = new Xamarin.Forms.Maps.Polyline()
            {
                StrokeWidth = 6,
                StrokeColor = Color.FromHex("#1BA1E2")
            };

            foreach (var coordinates in steps)
            {
                var position = new Position(coordinates.Latitude, coordinates.Longitude);
                polyline.Geopath.Add(position);
            }

            map.MapElements.Add(polyline);

            map.Pins.Add(new Pin()
            {
                Position = polyline.Geopath.First(),
                Label    = "Origin",
                Type     = PinType.SavedPin
            });

            map.Pins.Add(new Pin()
            {
                Position = polyline.Geopath.Last(),
                Label    = "Destination",
                Type     = PinType.SavedPin
            });
        }
Example #2
0
        protected void AddPolylineToMap(Xamarin.Forms.Maps.Polyline routeLine)
        {
            //remove old route lines
            foreach (MapElement element in map.MapElements.ToList())
            {
                if (element.GetType() == typeof(Xamarin.Forms.Maps.Polyline))
                {
                    map.MapElements.Remove(element);
                }
            }

            //put new line on map
            map.MapElements.Add(routeLine);
        }
Example #3
0
        protected override PolylineOptions CreatePolylineOptions(Xamarin.Forms.Maps.Polyline polyline)
        {
            if (polyline is MapPolyline positionPolyline)
            {
                positionPolyline.GenerateGeoPath();
            }

            var options = base.CreatePolylineOptions(polyline);

            if (polyline is MapPolyline mapPolyline)
            {
                options.InvokeZIndex(mapPolyline.ZIndex);
            }

            return(options);
        }
Example #4
0
        public MapElementsGallery()
        {
            InitializeComponent();

            Map.MoveToRegion(
                MapSpan.FromCenterAndRadius(
                    new Position(39.828152, -98.569817),
                    Distance.FromMiles(1681)));

            _polyline = new Maps.Polyline
            {
                Geopath =
                {
                    new Position(47.641944, -122.127222),
                    new Position(37.411625, -122.071327),
                    new Position(35.138901, -80.922623)
                }
            };

            _polygon = new Maps.Polygon
            {
                StrokeColor = Color.FromHex("#002868"),
                FillColor   = Color.FromHex("#88BF0A30"),
                Geopath     =
                {
                    new Position(37, -102.05),
                    new Position(37, -109.05),
                    new Position(41, -109.05),
                    new Position(41, -102.05)
                }
            };

            _circle = new Circle
            {
                Center      = new Position(42.352364, -71.067177),
                Radius      = Distance.FromMiles(100.0),
                StrokeColor = Color.FromRgb(31, 174, 206),
                FillColor   = Color.FromRgba(31, 174, 206, 127)
            };

            Map.MapElements.Add(_polyline);
            Map.MapElements.Add(_polygon);
            Map.MapElements.Add(_circle);

            ElementPicker.SelectedIndex = 0;
        }
Example #5
0
        void AddClicked(object sender, EventArgs e)
        {
            switch (_selectedType)
            {
            case SelectedElementType.Polyline:
                Map.MapElements.Add(_polyline = new Maps.Polyline());
                break;

            case SelectedElementType.Polygon:
                Map.MapElements.Add(_polygon = new Maps.Polygon());
                break;

            case SelectedElementType.Circle:
                Map.MapElements.Add(_circle = new Circle());
                break;
            }
        }
Example #6
0
        void RemoveClicked(object sender, EventArgs e)
        {
            switch (_selectedType)
            {
            case SelectedElementType.Polyline:
                Map.MapElements.Remove(_polyline);
                _polyline = Map.MapElements.OfType <Maps.Polyline>().LastOrDefault();

                if (_polyline == null)
                {
                    Map.MapElements.Add(_polyline = new Maps.Polyline());
                }

                break;

            case SelectedElementType.Polygon:
                Map.MapElements.Remove(_polygon);
                _polygon = Map.MapElements.OfType <Maps.Polygon>().LastOrDefault();

                if (_polygon == null)
                {
                    Map.MapElements.Add(_polygon = new Maps.Polygon());
                }

                break;

            case SelectedElementType.Circle:
                Map.MapElements.Remove(_circle);
                _circle = Map.MapElements.OfType <Circle>().LastOrDefault();

                if (_circle == null)
                {
                    Map.MapElements.Add(_circle = new Circle());
                }

                break;
            }
        }
        public async Task AddPolylineAsync()
        {
            if (!IsBusy)
            {
                try
                {
                    IsBusy        = true;
                    RouteDuration = null;
                    RouteDistance = null;
                    var current = Xamarin.Essentials.Connectivity.NetworkAccess;

                    if (current != Xamarin.Essentials.NetworkAccess.Internet)
                    {
                        // connection is not available
                        await DisplayAlert("Error", "You must be connected to the internet", "OK");

                        return;
                    }
                    if (Origin == null || Destination == null)
                    {
                        // no start or end point
                        await DisplayAlert("Error", "Origin and Destination must not be empty", "OK");

                        return;
                    }

                    myMap.MapElements.Clear();
                    myMap.Pins.Clear();
                    List <Route> routes = new List <Route>();
                    List <Leg>   legs   = new List <Leg>();
                    List <Step>  steps  = new List <Step>();
                    //List<Intersection> steps = new List<Step>();
                    List <Position> locations = new List <Position>();


                    dr = await rService.GetDirectionsResponseAsync(Origin, Destination);

                    if (dr == null)
                    {
                        await DisplayAlert("Error", "Route could not be found", "OK");

                        return;
                    }

                    if (dr != null)
                    {
                        routes = dr.Routes;

                        RouteDuration = routes[2].legs[0].duration;
                        RouteDistance = routes[2].legs[0].distance;

                        //routes[0].legs[0].

                        foreach (var route in routes)
                        {
                            legs = route.legs;
                        }

                        foreach (var leg in legs)
                        {
                            steps = leg.steps;
                        }
                        string encodedPoly = routes[0].overview_polyline.points;

                        List <Position> lines = DecodePolyline(encodedPoly);
                        Polyline        poli  = new Polyline()
                        {
                            StrokeColor = Color.Blue,
                            StrokeWidth = 10
                        };

                        for (int x = 0; x < lines.Count - 1; x++)
                        {
                            poli.Geopath.Add(lines[x]);
                        }

                        myMap.MapElements.Add(poli);

                        /*   var polylineOptions = new PolylineOptions()
                         *              .InvokeColor(Android.Graphics.Color.Blue)
                         *              .InvokeWidth(4);   */

                        ArrayList routePosList = new ArrayList();
                        foreach (var item in lines)
                        {
                            routePosList.Add(item);
                        }

                        // i have the polyline encoded, i have decoded it.. but cant set the geopath. what now?
                    }
                }
                catch
                {
                }
            }
        }
Example #8
0
        private async void btn32_Clicked(object sender, EventArgs e)
        {
            Mapa1.IsShowingUser      = true;
            MyStackLayout.IsVisible  = false;
            MyStackLayout1.IsVisible = false;
            MyStackLayout2.IsVisible = false;
            MyStackLayout3.IsVisible = false;
            MyStackLayout4.IsVisible = false;
            MyStackLayout5.IsVisible = false;

            btn32.TextColor       = Color.DarkRed;
            btn32.BackgroundColor = Color.White;
            btn32.FontAttributes  = FontAttributes.Bold;
            //   Stack2.IsVisible = false;

            btn2.BackgroundColor = Color.DarkRed;
            btn2.TextColor       = Color.White;
            btn3.BackgroundColor = Color.DarkRed;
            btn3.TextColor       = Color.White;
            var listApartmana = await _apartmani.Get <IList <Model.Apartmani> >(null);

            var listaAtrakcija = await _atrakcije.Get <IList <Model.Atrakcije> >(null);

            var listaKafica = await _kafici.Get <IList <Model.Kafici> >(null);

            var listaHotela = await _hoteli.Get <IList <Model.Hoteli> >(null);

            var listaRestorana = await _restorani.Get <IList <Model.Restorani> >(null);

            var listaNk = await _nocniklubovi.Get <IList <Model.Nightclubs> >(null);

            StackMapa.IsVisible = true;
            var request = new GeolocationRequest(GeolocationAccuracy.Best, TimeSpan.FromSeconds(10));

            cts = new CancellationTokenSource();
            tcs = new TaskCompletionSource <PermissionStatus>();
            var location = await Geolocation.GetLocationAsync(request, cts.Token);

            var      client   = new System.Net.Http.HttpClient();
            Position position = new Position(location.Latitude, location.Longitude);

            MapSpan mapSpan = MapSpan.FromCenterAndRadius(position, Distance.FromKilometers(0.444));

            Mapa1.MoveToRegion(mapSpan);
            if (APIService.Atraction)
            {
                foreach (var item in listaAtrakcija)
                {
                    Pin pin = new Pin
                    {
                        Label    = item.Naziv,
                        Address  = item.Lokacija,
                        Type     = PinType.Place,
                        Position = new Position((double)item.Latitude, (double)item.Longitude)
                    };
                    Mapa1.Pins.Add(pin);
                    var    lat1       = item.Latitude;
                    var    lon1       = item.Longitude;
                    var    lat2       = location.Latitude;
                    var    lon2       = location.Longitude;
                    string trazeniUrl = @"https://maps.googleapis.com/maps/api/directions/json?origin=" + lat2 + "," + lon2 + "&destination=" + lat1 + "," + lon1 + "&key=AIzaSyDP-0g1tNQWjpbUKC0uLv3tJ7GGm6a3t8Q";
                    var    response   = await client.GetAsync(trazeniUrl);

                    string contactsJson = await response.Content.ReadAsStringAsync(); //Getting response


                    GoogleDirection ObjContactList = new GoogleDirection();
                    if (response != null)
                    {
                        ObjContactList = JsonConvert.DeserializeObject <GoogleDirection>(contactsJson);
                    }
                    Xamarin.Forms.Maps.Polyline polyline = new Xamarin.Forms.Maps.Polyline
                    {
                        StrokeColor = Color.Blue,
                        StrokeWidth = 12,
                    };
                    var brojRouta = ObjContactList.Routes[0].Legs[0].Steps.Count();


                    for (int i = 0; i < brojRouta; i++)
                    {
                        polyline.Geopath.Add(new Position(ObjContactList.Routes[0].Legs[0].Steps[i].StartLocation.Lat, ObjContactList.Routes[0].Legs[0].Steps[i].StartLocation.Lng));
                        polyline.Geopath.Add(new Position(ObjContactList.Routes[0].Legs[0].Steps[i].EndLocation.Lat, ObjContactList.Routes[0].Legs[0].Steps[i].EndLocation.Lng));
                    }
                    Mapa1.MapElements.Add(polyline);
                }
            }
            if (APIService.Apartments)
            {
                foreach (var item in listApartmana)
                {
                    Pin pin = new Pin
                    {
                        Label    = item.Naziv,
                        Address  = item.Lokacija,
                        Type     = PinType.Place,
                        Position = new Position((double)item.Latitude, (double)item.Longitude)
                    };
                    Mapa1.Pins.Add(pin);
                    var    lat1       = item.Latitude;
                    var    lon1       = item.Longitude;
                    var    lat2       = location.Latitude;
                    var    lon2       = location.Longitude;
                    string trazeniUrl = @"https://maps.googleapis.com/maps/api/directions/json?origin=" + lat2 + "," + lon2 + "&destination=" + lat1 + "," + lon1 + "&key=AIzaSyDP-0g1tNQWjpbUKC0uLv3tJ7GGm6a3t8Q";
                    var    response   = await client.GetAsync(trazeniUrl);

                    string contactsJson = await response.Content.ReadAsStringAsync(); //Getting response

                    GoogleDirection ObjContactList = new GoogleDirection();
                    if (response != null)
                    {
                        ObjContactList = JsonConvert.DeserializeObject <GoogleDirection>(contactsJson);
                    }
                    Xamarin.Forms.Maps.Polyline polyline = new Xamarin.Forms.Maps.Polyline
                    {
                        StrokeColor = Color.Blue,
                        StrokeWidth = 12,
                    };
                    var brojRouta = ObjContactList.Routes[0].Legs[0].Steps.Count();


                    for (int i = 0; i < brojRouta; i++)
                    {
                        polyline.Geopath.Add(new Position(ObjContactList.Routes[0].Legs[0].Steps[i].StartLocation.Lat, ObjContactList.Routes[0].Legs[0].Steps[i].StartLocation.Lng));
                        polyline.Geopath.Add(new Position(ObjContactList.Routes[0].Legs[0].Steps[i].EndLocation.Lat, ObjContactList.Routes[0].Legs[0].Steps[i].EndLocation.Lng));
                    }
                    Mapa1.MapElements.Add(polyline);
                }
            }
            if (APIService.Food)
            {
                foreach (var item in listaRestorana)
                {
                    Pin pin = new Pin
                    {
                        Label    = item.Naziv,
                        Address  = item.Lokacija,
                        Type     = PinType.Place,
                        Position = new Position((double)item.Latitude, (double)item.Longitude)
                    };
                    Mapa1.Pins.Add(pin);
                    var    lat1       = item.Latitude;
                    var    lon1       = item.Longitude;
                    var    lat2       = location.Latitude;
                    var    lon2       = location.Longitude;
                    string trazeniUrl = @"https://maps.googleapis.com/maps/api/directions/json?origin=" + lat2 + "," + lon2 + "&destination=" + lat1 + "," + lon1 + "&key=AIzaSyDP-0g1tNQWjpbUKC0uLv3tJ7GGm6a3t8Q";
                    var    response   = await client.GetAsync(trazeniUrl);

                    string contactsJson = await response.Content.ReadAsStringAsync(); //Getting response

                    GoogleDirection ObjContactList = new GoogleDirection();
                    if (response != null)
                    {
                        ObjContactList = JsonConvert.DeserializeObject <GoogleDirection>(contactsJson);
                    }
                    Xamarin.Forms.Maps.Polyline polyline = new Xamarin.Forms.Maps.Polyline
                    {
                        StrokeColor = Color.Blue,
                        StrokeWidth = 12,
                    };
                    var brojRouta = ObjContactList.Routes[0].Legs[0].Steps.Count();


                    for (int i = 0; i < brojRouta; i++)
                    {
                        polyline.Geopath.Add(new Position(ObjContactList.Routes[0].Legs[0].Steps[i].StartLocation.Lat, ObjContactList.Routes[0].Legs[0].Steps[i].StartLocation.Lng));
                        polyline.Geopath.Add(new Position(ObjContactList.Routes[0].Legs[0].Steps[i].EndLocation.Lat, ObjContactList.Routes[0].Legs[0].Steps[i].EndLocation.Lng));
                    }
                    Mapa1.MapElements.Add(polyline);
                }
            }
            if (APIService.Nightclubs)
            {
                foreach (var item in listaNk)
                {
                    Pin pin = new Pin
                    {
                        Label    = item.Naziv,
                        Address  = item.Lokacija,
                        Type     = PinType.Place,
                        Position = new Position((double)item.Latitude, (double)item.Longitude)
                    };
                    Mapa1.Pins.Add(pin);
                    var    lat1       = item.Latitude;
                    var    lon1       = item.Longitude;
                    var    lat2       = location.Latitude;
                    var    lon2       = location.Longitude;
                    string trazeniUrl = @"https://maps.googleapis.com/maps/api/directions/json?origin=" + lat2 + "," + lon2 + "&destination=" + lat1 + "," + lon1 + "&key=AIzaSyDP-0g1tNQWjpbUKC0uLv3tJ7GGm6a3t8Q";
                    var    response   = await client.GetAsync(trazeniUrl);

                    string contactsJson = await response.Content.ReadAsStringAsync(); //Getting response

                    GoogleDirection ObjContactList = new GoogleDirection();
                    if (response != null)
                    {
                        ObjContactList = JsonConvert.DeserializeObject <GoogleDirection>(contactsJson);
                    }
                    Xamarin.Forms.Maps.Polyline polyline = new Xamarin.Forms.Maps.Polyline
                    {
                        StrokeColor = Color.Blue,
                        StrokeWidth = 12,
                    };
                    var brojRouta = ObjContactList.Routes[0].Legs[0].Steps.Count();


                    for (int i = 0; i < brojRouta; i++)
                    {
                        polyline.Geopath.Add(new Position(ObjContactList.Routes[0].Legs[0].Steps[i].StartLocation.Lat, ObjContactList.Routes[0].Legs[0].Steps[i].StartLocation.Lng));
                        polyline.Geopath.Add(new Position(ObjContactList.Routes[0].Legs[0].Steps[i].EndLocation.Lat, ObjContactList.Routes[0].Legs[0].Steps[i].EndLocation.Lng));
                    }
                    Mapa1.MapElements.Add(polyline);
                }
            }
            if (APIService.Coffeeshops)
            {
                foreach (var item in listaKafica)
                {
                    Pin pin = new Pin
                    {
                        Label    = item.Naziv,
                        Address  = item.Lokacija,
                        Type     = PinType.Place,
                        Position = new Position((double)item.Latitude, (double)item.Longitude)
                    };
                    Mapa1.Pins.Add(pin);
                    var    lat1       = item.Latitude;
                    var    lon1       = item.Longitude;
                    var    lat2       = location.Latitude;
                    var    lon2       = location.Longitude;
                    string trazeniUrl = @"https://maps.googleapis.com/maps/api/directions/json?origin=" + lat2 + "," + lon2 + "&destination=" + lat1 + "," + lon1 + "&key=AIzaSyDP-0g1tNQWjpbUKC0uLv3tJ7GGm6a3t8Q";
                    var    response   = await client.GetAsync(trazeniUrl);

                    string contactsJson = await response.Content.ReadAsStringAsync(); //Getting response

                    GoogleDirection ObjContactList = new GoogleDirection();
                    if (response != null)
                    {
                        ObjContactList = JsonConvert.DeserializeObject <GoogleDirection>(contactsJson);
                    }
                    Xamarin.Forms.Maps.Polyline polyline = new Xamarin.Forms.Maps.Polyline
                    {
                        StrokeColor = Color.Blue,
                        StrokeWidth = 12,
                    };
                    var brojRouta = ObjContactList.Routes[0].Legs[0].Steps.Count();


                    for (int i = 0; i < brojRouta; i++)
                    {
                        polyline.Geopath.Add(new Position(ObjContactList.Routes[0].Legs[0].Steps[i].StartLocation.Lat, ObjContactList.Routes[0].Legs[0].Steps[i].StartLocation.Lng));
                        polyline.Geopath.Add(new Position(ObjContactList.Routes[0].Legs[0].Steps[i].EndLocation.Lat, ObjContactList.Routes[0].Legs[0].Steps[i].EndLocation.Lng));
                    }
                    Mapa1.MapElements.Add(polyline);
                }
            }
        }
Example #9
0
        public async void AddPins()
        {
            var listApartmana = await _apartmani.Get <IList <Model.Apartmani> >(null);

            var listaAtrakcija = await _atrakcije.Get <IList <Model.Atrakcije> >(null);

            var listaKafica = await _kafici.Get <IList <Model.Kafici> >(null);

            var listaHotela = await _hoteli.Get <IList <Model.Hoteli> >(null);

            var listaRestorana = await _restorani.Get <IList <Model.Restorani> >(null);

            var listaNk = await _nocniklubovi.Get <IList <Model.Nightclubs> >(null);

            object trazeniModel = null;

            foreach (var item in listApartmana)
            {
                string lowerSearch  = APIService.SearchCon.ToLower();
                string lowerLetters = item.Naziv.ToLower();
                if (lowerLetters.Contains(lowerSearch))
                {
                    trazeniModel = item;

                    temp.Add(new Model.ReportClass {
                        Naziv = item.Naziv, Ocjena = item.Ocjena, Vrsta = item.Vrsta, Latitude = item.Latitude, Longitude = item.Longitude, Adresa = item.Lokacija
                    });
                }
            }

            foreach (var item in listaAtrakcija)
            {
                string lowerSearch  = APIService.SearchCon.ToLower();
                string lowerLetters = item.Naziv.ToLower();
                if (lowerLetters.Contains(lowerSearch))
                {
                    trazeniModel = item;
                    temp.Add(new Model.ReportClass {
                        Naziv = item.Naziv, Ocjena = item.Ocjena, Vrsta = item.Vrsta, Latitude = item.Latitude, Longitude = item.Longitude, Adresa = item.Lokacija
                    });
                }
            }



            foreach (var item in listaHotela)
            {
                string lowerSearch  = APIService.SearchCon.ToLower();
                string lowerLetters = item.Naziv.ToLower();
                if (lowerLetters.Contains(lowerSearch))
                {
                    trazeniModel = item;
                    temp.Add(new Model.ReportClass {
                        Naziv = item.Naziv, Ocjena = item.Ocjena, Vrsta = "Hotel", Latitude = item.Latitude, Longitude = item.Longitude, Adresa = item.Lokacija
                    });
                }
            }



            foreach (var item in listaKafica)
            {
                string lowerSearch  = APIService.SearchCon.ToLower();
                string lowerLetters = item.Naziv.ToLower();
                if (lowerLetters.Contains(lowerSearch))
                {
                    trazeniModel = item;
                    temp.Add(new Model.ReportClass {
                        Naziv = item.Naziv, Ocjena = item.Ocjena, Vrsta = "Kafic", Latitude = item.Latitude, Longitude = item.Longitude, Adresa = item.Lokacija
                    });
                }
            }


            foreach (var item in listaRestorana)
            {
                string lowerSearch  = APIService.SearchCon.ToLower();
                string lowerLetters = item.Naziv.ToLower();
                if (lowerLetters.Contains(lowerSearch))
                {
                    trazeniModel = item;
                    temp.Add(new Model.ReportClass {
                        Naziv = item.Naziv, Ocjena = item.Ocjena, Vrsta = "Restoran", Latitude = item.Latitude, Longitude = item.Longitude, Adresa = item.Lokacija
                    });
                }
            }


            foreach (var item in listaNk)
            {
                string lowerSearch  = APIService.SearchCon.ToLower();
                string lowerLetters = item.Naziv.ToLower();
                if (lowerLetters.Contains(lowerSearch))
                {
                    trazeniModel = item;
                    temp.Add(new Model.ReportClass {
                        Naziv = item.Naziv, Ocjena = item.Ocjena, Vrsta = "Nightclub", Latitude = item.Latitude, Longitude = item.Longitude, Adresa = item.Lokacija
                    });
                }
            }
            var request = new GeolocationRequest(GeolocationAccuracy.Best, TimeSpan.FromSeconds(10));

            cts = new CancellationTokenSource();
            tcs = new TaskCompletionSource <PermissionStatus>();
            var location = await Geolocation.GetLocationAsync(request, cts.Token);

            var client = new System.Net.Http.HttpClient();

            foreach (var item in temp)
            {
                Pin pin = new Pin
                {
                    Label    = item.Naziv,
                    Address  = item.Adresa,
                    Type     = PinType.Place,
                    Position = new Position((double)item.Latitude, (double)item.Longitude)
                };
                Mapa.Pins.Add(pin);


                var    lat1       = item.Latitude;
                var    lon1       = item.Longitude;
                var    lat2       = location.Latitude;
                var    lon2       = location.Longitude;
                string trazeniUrl = @"https://maps.googleapis.com/maps/api/directions/json?origin=" + lat2 + "," + lon2 + "&destination=" + lat1 + "," + lon1 + "&key=AIzaSyDP-0g1tNQWjpbUKC0uLv3tJ7GGm6a3t8Q";
                var    response   = await client.GetAsync(trazeniUrl);

                string contactsJson = await response.Content.ReadAsStringAsync(); //Getting response

                GoogleDirection ObjContactList = new GoogleDirection();
                if (response != null)
                {
                    ObjContactList = JsonConvert.DeserializeObject <GoogleDirection>(contactsJson);
                }
                Xamarin.Forms.Maps.Polyline polyline = new Xamarin.Forms.Maps.Polyline
                {
                    StrokeColor = Color.Blue,
                    StrokeWidth = 12,
                };
                var brojRouta = ObjContactList.Routes[0].Legs[0].Steps.Count();


                for (int i = 0; i < brojRouta; i++)
                {
                    polyline.Geopath.Add(new Position(ObjContactList.Routes[0].Legs[0].Steps[i].StartLocation.Lat, ObjContactList.Routes[0].Legs[0].Steps[i].StartLocation.Lng));
                    polyline.Geopath.Add(new Position(ObjContactList.Routes[0].Legs[0].Steps[i].EndLocation.Lat, ObjContactList.Routes[0].Legs[0].Steps[i].EndLocation.Lng));
                }
                Mapa.MapElements.Add(polyline);
            }
        }