Пример #1
0
        /* Spans the map over the buildings and lots that are selected by the parameters
         * Parameters: string (the name of the campus the building is in),
         *  string (the name of the building that is spanned over), List<int> (the list of lotIds to span over)
         */
        public void SpanToLotsAndBuildings(string campusName, string buildingName, List <int> lotOrder)
        {
            var ls            = new List <Position>();
            int lotOrderCount = lotOrder.Count;

            if (lotOrderCount > 3)
            {
                lotOrderCount = 3;
            }

            foreach (Campus campus in mCampuses)
            {
                if (campus.GetName() == campusName)
                {
                    for (int i = 0; i < lotOrderCount; i++)
                    {
                        foreach (Position pos in campus.GetLotPoints(lotOrder[i].ToString()))
                        {
                            ls.Add(pos);
                        }
                    }

                    foreach (Position pos in campus.GetBuildingEntrances(buildingName))
                    {
                        ls.Add(pos);
                    }
                }
            }

            MoveToRegion(MapSpan.FromPositions(ls));
        }
Пример #2
0
        /* Spans the map over the building that is selected by the parameters
         * Parameters: string (the name of the building to be spanned over),
         *  string (the name of the campus the building is in)
         */
        public async void SpanToBuilding(string buildingName, string campusName)
        {
            foreach (Campus campus in mCampuses)
            {
                if (campus.GetName() == campusName)
                {
                    foreach (Building building in campus.Buildings)
                    {
                        if (buildingName == building.GetName())
                        {
                            List <Position> ls = new List <Position>();

                            foreach (Location loc in building.Entrances)
                            {
                                ls.Add(new Position(loc.Lat, loc.Long));
                            }

                            MoveToRegion(MapSpan.FromPositions(ls));
                            break;
                        }
                    }
                    break;
                }
            }
        }
Пример #3
0
        static void onCenterPositionsChanged(BindableObject bindable, object oldValue, object newValue)
        {
            var map = bindable as Map;

            if (map != null)
            {
                var positions = newValue as IList <Position>;
                if (positions != null)
                {
                    map.MoveToRegion(MapSpan.FromPositions(positions));
                }
            }
        }
Пример #4
0
        async void OnDataSourceChanged()
        {
            var dataSource = DataSource as JsonDataSource;
            await dataSource.ParseJson();

            var positions = new List <Position>();

            foreach (var dataItem in DataSource.Data)
            {
                try
                {
                    var item  = dataItem.Value as IDataSource;
                    var title = item["title"].ToString();
                    var room  = item["presenter"].ToString();
                    var lat   = (float)item["lat"];
                    var lon   = (float)item["lon"];

                    positions.Add(new Position(lat, lon));

                    var pin = new Pin
                    {
                        Icon     = BitmapDescriptorFactory.FromBundle("coffee"),
                        Type     = PinType.Place,
                        Label    = room,
                        Address  = title,
                        Position = new Position(lat, lon),
                        Tag      = dataItem
                    };

                    pin.Clicked += Pin_Clicked;

                    map.Pins.Add(pin);
                }
                catch (Exception ex)
                {
                }
            }

            map.MoveToRegion(MapSpan.FromPositions(positions), true);
        }
Пример #5
0
        private void SetupMerchantsView(bool affectCurrentRegion = true)
        {
            MapView.Pins.Clear();
            foreach (var merchant in _merchants)
            {
                MapView.Pins.Add(new Pin()
                {
                    Address  = merchant.Location,
                    Position = new Position(merchant.LocationLat, merchant.LocationLng),
                    Label    = merchant.Name,
                    Type     = PinType.Place,
                    Icon     = MapIconDescriptor,
                    Tag      = merchant,
                });
            }

            //
            if (affectCurrentRegion)
            {
                MapView.MoveToRegion(MapSpan.FromPositions(_merchants.Select(x => new Position(x.LocationLat, x.LocationLng))));
            }
        }
Пример #6
0
        async void Calculate(List <Xamarin.Forms.GoogleMaps.Position> list)
        {
            searchLayout.IsVisible    = true;
            stopRouteButton.IsVisible = false;
            Chamada.IsVisible         = true;

            map.Polylines.Clear();
            var polyline = new Xamarin.Forms.GoogleMaps.Polyline();


            polyline.StrokeColor = Color.Green;

            polyline.StrokeWidth = (float)5;



            foreach (var p in list)
            {
                polyline.Positions.Add(p);
            }
            map.Polylines.Add(polyline);


            var pin = new Xamarin.Forms.GoogleMaps.Pin
            {
                Type     = PinType.Place,
                Position = new Xamarin.Forms.GoogleMaps.Position(polyline.Positions.First().Latitude, polyline.Positions.First().Longitude),
                Label    = "First",
                Address  = "First",
                Tag      = string.Empty,
                Icon     = BitmapDescriptorFactory.FromView(new Image()
                {
                    Source = "ic_taxi.png", WidthRequest = 25, HeightRequest = 25
                })
            };

            map.Pins.Add(pin);

            var pin1 = new Xamarin.Forms.GoogleMaps.Pin
            {
                Type     = PinType.Place,
                Position = new Xamarin.Forms.GoogleMaps.Position(polyline.Positions.Last().Latitude, polyline.Positions.Last().Longitude),
                Label    = "Last",
                Address  = "Last",
                Tag      = string.Empty
            };

            map.Pins.Add(pin1);



            //var medio = polyline.Positions.Count/ 2;


            //var pinmedio = new Xamarin.Forms.GoogleMaps.Pin
            //{
            //Type = PinType.Place,

            //Position = new Position(polyline.Positions[medio].Latitude, polyline.Positions[medio].Longitude),

            //Label = "Medio",
            //Address = "Medio",
            //Tag = string.Empty,

            //};

            //map.Pins.Add(pinmedio);



            inicio = pin.Position;

            fim = pin1.Position;

            map.MoveToRegion(MapSpan.FromPositions(list).WithZoom(0.85));

            await StartListening();
        }
Пример #7
0
        void Calculate(List <Xamarin.Forms.GoogleMaps.Position> list)
        {
            mapn.Polylines.Clear();
            var polygon = new Xamarin.Forms.GoogleMaps.Polygon();

            polygon.Positions.Add(new Position(41.1389019841448d, -8.61560349288011d));
            polygon.Positions.Add(new Position(41.1434744495776d, -8.67074812896517d));
            polygon.Positions.Add(new Position(41.1449838609599d, -8.67905202242122d));
            polygon.Positions.Add(new Position(41.1451299199957d, -8.67927438576518d));
            polygon.Positions.Add(new Position(41.1667491884192d, -8.69051961393614d));
            polygon.Positions.Add(new Position(41.1687515832633d, -8.69128901091482d));
            polygon.Positions.Add(new Position(41.1687718202548d, -8.69129406942044d));
            polygon.Positions.Add(new Position(41.1733985483824d, -8.6901233398917d));
            polygon.Positions.Add(new Position(41.1791950462077d, -8.66638025932549d));
            polygon.Positions.Add(new Position(41.1843186499419d, -8.64263275539779d));
            polygon.Positions.Add(new Position(41.1859199810206d, -8.60475022412726d));
            polygon.Positions.Add(new Position(41.1859353051989d, -8.60415557268555d));
            polygon.Positions.Add(new Position(41.1858564905415d, -8.60352615847566d));
            polygon.Positions.Add(new Position(41.1809534888858d, -8.57618203495341d));
            polygon.Positions.Add(new Position(41.1808879776888d, -8.57596086663742d));
            polygon.Positions.Add(new Position(41.1782338392238d, -8.56918812805673d));
            polygon.Positions.Add(new Position(41.1781107344154d, -8.5690029395442d));
            polygon.Positions.Add(new Position(41.1778608190979d, -8.56863743584061d));
            polygon.Positions.Add(new Position(41.1776820677363d, -8.56838121049044d));
            polygon.Positions.Add(new Position(41.1772845426276d, -8.56783274898752d));
            polygon.Positions.Add(new Position(41.1761404097255d, -8.56630188826643d));
            polygon.Positions.Add(new Position(41.1760550093552d, -8.56619263815834d));
            polygon.Positions.Add(new Position(41.1759695143603d, -8.56610877045314d));
            polygon.Positions.Add(new Position(41.1600578943756d, -8.55337925107515d));
            polygon.Positions.Add(new Position(41.158207085713d, -8.55261345505833d));
            polygon.Positions.Add(new Position(41.1532077014578d, -8.55473745611279d));
            polygon.Positions.Add(new Position(41.1529458174769d, -8.55494508426352d));
            polygon.Positions.Add(new Position(41.1463677636723d, -8.56368877972558d));
            polygon.Positions.Add(new Position(41.1399578511665d, -8.57576315330342d));
            polygon.Positions.Add(new Position(41.1383506797128d, -8.59418349674972d));

            polygon.IsClickable = true;
            polygon.StrokeColor = Color.Black;
            polygon.StrokeWidth = 3f;
            polygon.FillColor   = Color.FromRgba(255, 0, 0, 64);
            polygon.Tag         = "POLYGON";

            mapn.Polygons.Add(polygon);

            var polyline = new Xamarin.Forms.GoogleMaps.Polyline();

            polyline.StrokeColor = Color.Blue;
            polyline.StrokeWidth = polyline.StrokeWidth * 4;
            var polylineinside = new Xamarin.Forms.GoogleMaps.Polyline();

            polylineinside.StrokeColor = Color.Red;
            polylineinside.StrokeWidth = polyline.StrokeWidth * 2;

            foreach (var p in list)
            {
                polyline.Positions.Add(p);
                if (Contains(p, polygon))
                {
                    // point is inside polygon
                    polylineinside.Positions.Add(p);
                }
            }
            mapn.Polylines.Add(polyline);
            if (polylineinside.Positions.Count > 2)
            {
                mapn.Polylines.Add(polylineinside);
            }

            var pin = new Xamarin.Forms.GoogleMaps.Pin
            {
                Type     = PinType.Place,
                Position = new Position(polyline.Positions.First().Latitude, polyline.Positions.First().Longitude),
                Label    = vm.startLabel,
                Address  = vm.startAdd,
                Tag      = "First Point",
                Icon     = BitmapDescriptorFactory.FromView(new Image()
                {
                    Source = "ic_location.png", WidthRequest = 25, HeightRequest = 25
                })
            };

            mapn.Pins.Add(pin);
            var pin1 = new Xamarin.Forms.GoogleMaps.Pin
            {
                Type     = PinType.Place,
                Position = new Position(polyline.Positions.Last().Latitude, polyline.Positions.Last().Longitude),
                Label    = vm.endLabel,
                Address  = vm.endAdd,
                Tag      = "Last Point",
                Icon     = BitmapDescriptorFactory.FromView(new Image()
                {
                    Source = "ic_location_red.png", WidthRequest = 25, HeightRequest = 25
                })
            };

            mapn.Pins.Add(pin1);
            int innerDist = 0;

            if (polylineinside.Positions.Count > 2)
            {
                var googleDirection = (vm.GetDistance(polylineinside.Positions.First(), polylineinside.Positions.Last()).Result);

                if (googleDirection.Routes != null && googleDirection.Routes.Count > 0)
                {
                    innerDist = googleDirection.Routes.FirstOrDefault().Legs.FirstOrDefault().Distance.Value;
                }
            }
            int     totalDist         = vm.CurrentGoogleDirection.Routes.FirstOrDefault().Legs.FirstOrDefault().Distance.Value;
            decimal totalfare         = 0;
            decimal distanceunit      = 0;
            decimal innerDistanceunit = 0;
            decimal outerDistanceunit = 0;
            int     outerDist         = totalDist - innerDist;
            decimal innerfare         = (47m / (1000m / 300m));
            decimal outerfare         = (94m / (1000m / 300m));

            if (innerDist > 0)
            {
                innerDistanceunit = (Convert.ToDecimal(innerDist) / 300m);
                outerDistanceunit = (Convert.ToDecimal(outerDist) / 300m);

                totalfare    = (innerfare * innerDistanceunit) + (outerfare * outerDistanceunit);
                distanceunit = innerDistanceunit + outerDistanceunit;
            }
            else
            {
                distanceunit = (totalDist / 300m);
                totalfare    = (outerfare * distanceunit);
            }


            mapn.MoveToRegion(MapSpan.FromPositions(list));

            App.Current.MainPage.DisplayAlert("Price", "Total Distance : " + totalDist + " & Total Price : " + totalfare.ToString("F2")
                                              + "\nOuter Distance : " + outerDist + " @ Price : 94 cents"
                                              + "\nInner Distance : " + innerDist + " @ Price : 47 cents", "Ok");
        }
Пример #8
0
        void Calculate(List <Xamarin.Forms.GoogleMaps.Position> list)
        {
            mapn.Polylines.Clear();
            Polygon polygon = Getpolygondata();

            mapn.Polygons.Add(polygon);

            var polyline = new Xamarin.Forms.GoogleMaps.Polyline();

            polyline.StrokeColor = Color.Blue;
            polyline.StrokeWidth = polyline.StrokeWidth * 4;
            var polylineinside = new Xamarin.Forms.GoogleMaps.Polyline();

            polylineinside.StrokeColor = Color.Red;
            polylineinside.StrokeWidth = polyline.StrokeWidth * 2;

            foreach (var p in list)
            {
                polyline.Positions.Add(p);
                if (Contains(p, polygon))
                {
                    // point is inside polygon
                    polylineinside.Positions.Add(p);
                }
            }

            mapn.Polylines.Add(polyline);
            if (polylineinside.Positions.Count > 2)
            {
                mapn.Polylines.Add(polylineinside);
            }

            var pin = new Xamarin.Forms.GoogleMaps.Pin
            {
                Type     = PinType.Place,
                Position = new Position(polyline.Positions.First().Latitude, polyline.Positions.First().Longitude),
                Label    = vm.StartLabel,
                Address  = vm.StartAdd,
                Tag      = "First Point",
                Icon     = BitmapDescriptorFactory.FromView(new Image()
                {
                    Source = "ic_location.png", WidthRequest = 25, HeightRequest = 25
                })
            };

            mapn.Pins.Add(pin);
            var pin1 = new Xamarin.Forms.GoogleMaps.Pin
            {
                Type     = PinType.Place,
                Position = new Position(polyline.Positions.Last().Latitude, polyline.Positions.Last().Longitude),
                Label    = vm.EndLabel,
                Address  = vm.EndAdd,
                Tag      = "Last Point",
                Icon     = BitmapDescriptorFactory.FromView(new Image()
                {
                    Source = "ic_location_red.png", WidthRequest = 25, HeightRequest = 25
                })
            };

            mapn.Pins.Add(pin1);
            int InnerDist = 0;

            if (polylineinside.Positions.Count > 2)
            {
                var googleDirection = (vm.GetDistance(polylineinside.Positions.First(), polylineinside.Positions.Last()).Result);

                if (googleDirection.Routes != null && googleDirection.Routes.Count > 0)
                {
                    InnerDist = googleDirection.Routes.FirstOrDefault().Legs.FirstOrDefault().Distance.Value;
                }
            }
            int     TotalDistance     = vm.CurrentGoogleDirection.Routes.FirstOrDefault().Legs.FirstOrDefault().Distance.Value;
            decimal TotalFare         = 0;
            decimal DistanceUnit      = 0;
            decimal InnerDistanceUnit = 0;
            decimal OuterDistanceUnit = 0;
            int     OuterDist         = TotalDistance - InnerDist;
            decimal InnerFare         = (Constants.InnerFareRate / (Constants.DistanceUnitKM / Constants.BillingUnit));
            decimal OuterFare         = (Constants.OuterFareRate / (Constants.DistanceUnitKM / Constants.BillingUnit));

            if (InnerDist > 0)
            {
                InnerDistanceUnit = (Convert.ToDecimal(InnerDist) / Constants.BillingUnit);
                OuterDistanceUnit = (Convert.ToDecimal(OuterDist) / Constants.BillingUnit);

                TotalFare    = (InnerFare * InnerDistanceUnit) + (OuterFare * OuterDistanceUnit);
                DistanceUnit = InnerDistanceUnit + OuterDistanceUnit;
            }
            else
            {
                DistanceUnit = (TotalDistance / Constants.BillingUnit);
                TotalFare    = (OuterFare * DistanceUnit);
            }


            mapn.MoveToRegion(MapSpan.FromPositions(list));

            App.Current.MainPage.DisplayAlert("Price", "Total Distance : " + TotalDistance + " & Total Price : " + TotalFare.ToString("F2")
                                              + "\nOuter Distance : " + OuterDist + " @ Price : " + Constants.OuterFareRate + " cents"
                                              + "\nInner Distance : " + InnerDist + " @ Price : " + Constants.InnerFareRate + " cents", "Ok");
        }
Пример #9
0
        protected override void OnAppearing()
        {
            base.OnAppearing();
            this.viewModel = this.BindingContext as MainViewModel;

            this.viewModel
            .WhenAnyValue(x => x.CurrentCoordinates)
            .Where(x => x != null)
            .Subscribe(coords =>
            {
                var current = new Position(coords.Latitude, coords.Longitude);
                this.MyMap.Pins.Clear();
                this.MyMap.Pins.Add(new Pin
                {
                    IsDraggable = false,
                    Address     = "Selected Location",
                    Label       = coords.ToString(),
                    Position    = current,
                    Type        = PinType.Generic
                });
            });

            this.viewModel
            .WhenAnyValue(x => x.ResolvedCityCoordinates)
            .Where(x => x != null)
            .Subscribe(coords =>
            {
                // this would always come after current
                var current = new Position(this.viewModel.CurrentCoordinates.Latitude,
                                           this.viewModel.CurrentCoordinates.Longitude);
                var position = new Position(coords.Latitude, coords.Longitude);

                this.MyMap.Pins.Add(new Pin
                {
                    Address  = this.viewModel.LocationName,
                    Label    = "Resolved City",
                    Position = position,
                    Type     = PinType.SearchResult,
                    Icon     = BitmapDescriptorFactory.DefaultMarker(Color.Fuchsia)
                });
                var line = new Polyline {
                    StrokeColor = Color.Red
                };
                line.Positions.Add(current);
                line.Positions.Add(position);

                this.MyMap.Polylines.Clear();
                this.MyMap.Polylines.Add(line);
            });

            this.viewModel
            .WhenZoomRequested()
            .Subscribe(_ =>
            {
                this.MyMap.MoveToRegion(MapSpan.FromPositions(new []
                {
                    this.viewModel.CurrentCoordinates.ToMapPosition(),
                    this.viewModel.ResolvedCityCoordinates.ToMapPosition()
                }));
            });

            this.viewModel.Start();
        }