Example #1
0
 public override void OnNavigatedTo(INavigationParameters parameters)
 {
     base.OnNavigatedTo(parameters);
     if (string.IsNullOrEmpty(Search))
     {
         PoIs     = new ObservableCollection <PointOfInterest>(_PoIService.GetAllPoI().OrderBy(poi => poi.Date));
         BasePoIs = PoIs;
     }
 }
Example #2
0
        async void CallingGPS()
        {
            var liste = poiservice.GetAllPoI();

            for (int i = 0; i < liste.Count; i++)
            {
                if (liste[i].latitude != 0 && liste[i].longitude != 0)
                {
                    Pin pin = new Pin
                    {
                        Type           = PinType.Place,
                        Position       = new Position(liste[i].latitude, liste[i].longitude),
                        Label          = liste[i].Name,
                        Address        = "#" + liste[i].Tag,
                        BindingContext = liste[i],
                    };

                    pin.Clicked += (sender, args) =>
                    {
                        var param = new NavigationParameters()
                        {
                            { "poi", pin.BindingContext },
                            { "source", "map" }
                        };

                        NavigationService.NavigateAsync("PoIDetail", param);
                    };

                    Map.Pins.Add(pin);
                }
            }

            var      locator = CrossGeolocator.Current;
            Position position;

            locator.DesiredAccuracy = 120;

            if (!CrossGeolocator.IsSupported)
            {
                position = new Position();
            }
            if (!CrossGeolocator.Current.IsGeolocationEnabled)
            {
                position = new Position();
            }
            if (!CrossGeolocator.Current.IsGeolocationAvailable)
            {
                position = new Position();
            }

            try
            {
                var ex = await locator.GetPositionAsync(TimeSpan.FromSeconds(10), null, false);

                position = new Position(ex.Latitude, ex.Longitude);
            }
            catch (Exception e)
            {
                if (liste.Count > 0)
                {
                    position = new Position(liste.FirstOrDefault().latitude, liste.FirstOrDefault().longitude);
                }
                else
                {
                    position = new Position();
                }
            }

            Map.MoveToRegion(MapSpan.FromCenterAndRadius(position, Distance.FromMiles(1)));
        }