private object GetPlace(dynamic parameters)
        {
            var place = (Place)Database.Open().Places.FindById((int)parameters.id);

            OSRef gridRef = null;

            if (!string.IsNullOrEmpty(place.GridReference))
            {
                try
                {
                    gridRef = new OSRef(Regex.Replace(place.GridReference, @"\s+", ""));
                }
                catch
                {
                    //dont care
                }
            }

            var representation = new HalBuilder(Request.Url.ToString())
                                 .AddPublicPropertiesOf(place)
                                 .ConditionallyAddProperty("longitude", gridRef != null, () => gridRef.ToLatLng().Longitude)
                                 .ConditionallyAddProperty("latitude", gridRef != null, () => gridRef.ToLatLng().Latitude)
                                 .Build();

            return(Response.AsJson(representation));
        }
Example #2
0
        private async void DoItButton_Click(object sender, RoutedEventArgs e)
        {
            DoItButton.IsEnabled = false;
            var accessStatus = await Geolocator.RequestAccessAsync();

            switch (accessStatus)
            {
                case GeolocationAccessStatus.Allowed:
                    NotifyUser("Waiting for update...", NotifyType.StatusMessage);

                    myProgressRing.IsActive = true;

                    // If DesiredAccuracy or DesiredAccuracyInMeters are not set (or value is 0), DesiredAccuracy.Default is used.
                    _geolocator = new Geolocator { DesiredAccuracyInMeters = _desireAccuracyInMetersValue };

                    // Subscribe to the StatusChanged event to get updates of location status changes.
                    _geolocator.StatusChanged += OnStatusChanged;

                    // Carry out the operation.
                    Geoposition pos = await _geolocator.GetGeopositionAsync();

                    // Convert to OS grid reference
                    var osRef = new OSRef(new LatLng(pos.Coordinate.Point.Position.Latitude, pos.Coordinate.Point.Position.Longitude));

                    //await new MessageDialog("OS grid reference = " +
                    //          osRef.ToSixFigureString()).ShowAsync();

                    var dlg = new GridRefDialog(osRef.ToSixFigureString());
                    dlg.Closed += (d, a) => DoItButton.IsEnabled = true;

                    myProgressRing.IsActive = false;

                    dlg.ShowAsync();
                    break;

                case GeolocationAccessStatus.Denied:
                    NotifyUser("Access to location is denied.", NotifyType.ErrorMessage);
                    LocationDisabledMessage.Visibility = Visibility.Visible;
                    break;

                case GeolocationAccessStatus.Unspecified:
                    NotifyUser("Unspecified error.", NotifyType.ErrorMessage);
                    break;
            }
        }