Ejemplo n.º 1
0
        public void AddCreatedPin(Position pos)
        {
            if (pos != null)
            {
                CreatedPins.Clear();

                var pin = new CustomPin();
                pin.Pin = new Pin()
                {
                    Type     = Xamarin.Forms.Maps.PinType.SavedPin,
                    Position = new Xamarin.Forms.Maps.Position(pos.Latitude, pos.Longitude),
                    Label    = "Created pin"
                };
                CreatedPins.Add(pin);
            }
        }
Ejemplo n.º 2
0
        public async Task <bool> InsertLoc(FishingLoc loc, bool fromFish = false)
        {
            if (loc == null)
            {
                loc = new FishingLoc();
            }
            Coordinate coor = new Coordinate()
            {
                IdCoordinate = Guid.NewGuid().ToString()
            };

            if (LocActivationSwitchState)
            {
                //From geolocator
                try
                {
                    var locator  = CrossGeolocator.Current;
                    var position = await locator.GetPositionAsync();

                    if (position != null)
                    {
                        coor.Lattitude = position.Latitude;
                        coor.Longitude = position.Longitude;
                    }
                }
                catch (Exception ex)
                {
                }
            }
            else
            {
                //from Selection
                loc.Name       = CurrentLoc.Name;
                loc.PlaceCount = CurrentLoc.PlaceCount;
                loc.Type       = CurrentLoc.Type;

                if (CreatedPins.Count == 1)
                {
                    foreach (var pin in CreatedPins)
                    {
                        coor.Lattitude = pin.Pin.Position.Latitude;
                        coor.Longitude = pin.Pin.Position.Longitude;
                    }
                }
            }
            Waypoint wp = new Waypoint()
            {
                Coordinate = coor, IdWaypoint = Guid.NewGuid().ToString()
            };

            loc.Waypoints.Add(wp);
            if (fromFish)
            {
                loc.Type       = "GPS";
                loc.Name       = null;
                loc.PlaceCount = 0;
            }
            else
            {
                loc.Type       = CurrentLoc.Type;
                loc.Name       = CurrentLoc.Name;
                loc.PlaceCount = CurrentLoc.PlaceCount;
            }

            loc.IdFishingLoc = Guid.NewGuid().ToString();
            loc.User_IdUser  = App.user.IdUser;
            FishingLoc.Insert(loc);
            CurrentLoc = new FishingLoc();
            CreatedPins.Clear();
            HomeViewModel.UpdateLocs();

            return(true);
        }