5 Replies - 2222 Views - Last Post: 22 March 2014 - 11:30 AM Rate Topic: -----

#1 ThomasHohner   User is offline

  • New D.I.C Head

Reputation: 2
  • View blog
  • Posts: 15
  • Joined: 10-March 14

Geolocation no errors but does not work?

Posted 21 March 2014 - 06:13 PM

Hello all,

I'm a noob and trying to learn C# part of that process for myself is reading books, watching tutorials and tinkering.

I'm currently messing around with geolocation and have this Windows App I'm working on. There is no errors or warnings when I run it, but it does not work. I click my Enable GPS button and nada, nothing, zilch. This isn't a important project or anything just a learning experience for myself. If any of you have time and wouldn't mind pointing me in the direction I need to go that would be stellar!

This is my C# portion if you need me to post the XAML side also I can do that as well.

Thanks again gentlemen!

using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices.WindowsRuntime;
using Windows.Foundation;
using Windows.Foundation.Collections;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Controls.Primitives;
using Windows.UI.Xaml.Data;
using Windows.UI.Xaml.Input;
using Windows.UI.Xaml.Media;
using Windows.UI.Xaml.Navigation;
using Windows.Devices.Geolocation;
using System.Threading.Tasks;
using Windows.UI.Core; 



namespace GeoSnapWindowsDesktop
{ 

    public sealed partial class MainPage : Page

    {

        private Geolocator geolocator = null;
       

  

        public MainPage()

        {

            this.InitializeComponent();

            geolocator  = new  Geolocator();

        }

  

        protected override void OnNavigatedTo(NavigationEventArgs e)

        {

            EnableGPS.IsEnabled = true;

        }

  

  

        async private void EnableGPS_Click(object sender, RoutedEventArgs e)

        {

            EnableGPS.IsEnabled = false;

  

            try

            {

                // Carry out the operation

                Geoposition pos = await  geolocator.GetGeopositionAsync();

               
                
              Latitude.Text = pos.Coordinate.Point.Position.Latitude.ToString();

                Longitude.Text = pos.Coordinate.Point.Position.Longitude.ToString();

                Accuracy.Text = pos.Coordinate.Accuracy.ToString();

                GPS_Status.Text = GetStatusString(geolocator.LocationStatus);

            }

            catch (System.UnauthorizedAccessException)

            {

                Latitude.Text = "No data";

                Longitude.Text = "No data";

                Accuracy.Text = "No data";

                GPS_Status.Text = "No data";

            }

            catch (TaskCanceledException)

            {

                Latitude.Text = "Cancelled";

                Longitude.Text = "Cancelled";

                Accuracy.Text = "Cancelled";

                GPS_Status.Text = "Cancelled";

            }

  

            EnableGPS.IsEnabled = true;

        }

  

  

         private string GetStatusString(PositionStatus status)

        {

                var strStatus = "";

  

                switch (status)

                {

                    case PositionStatus.Ready:

                        strStatus = "Location is available.";

                        break;

  

                    case PositionStatus.Initializing:

                        strStatus = "Geolocation service is initializing.";

                        break;

  

                    case PositionStatus.NoData:

                        strStatus = "Location service data is not available.";

                        break;

  

                    case PositionStatus.Disabled:

                        strStatus = "Location services are disabled. Use the " +

                                    "Settings charm to enable them.";

                        break;

  

                    case PositionStatus.NotInitialized:

                        strStatus = "Location status is not initialized because " +

                                    "the app has not yet requested location data.";

                        break;

  

                    case PositionStatus.NotAvailable:

                        strStatus = "Location services are not supported on your system.";

                        break;

  

                    default:

                        strStatus = "Unknown PositionStatus value.";

                        break;

                }

  

                return (strStatus);

  

        }




         public Geolocator geopostion { get; set; }
    }

}





Is This A Good Question/Topic? 0
  • +

Replies To: Geolocation no errors but does not work?

#2 Momerath   User is offline

  • D.I.C Lover
  • member icon

Reputation: 1021
  • View blog
  • Posts: 2,463
  • Joined: 04-October 09

Re: Geolocation no errors but does not work?

Posted 21 March 2014 - 06:38 PM

Have you tried putting a breakpoint after line 71 to see what is in pos? If you aren't getting errors, sounds like a display problem.

And what is the EnableGPS class and why do you turn it off right before you want GPS coords?

This post has been edited by Momerath: 21 March 2014 - 06:39 PM

Was This Post Helpful? 0
  • +
  • -

#3 ThomasHohner   User is offline

  • New D.I.C Head

Reputation: 2
  • View blog
  • Posts: 15
  • Joined: 10-March 14

Re: Geolocation no errors but does not work?

Posted 21 March 2014 - 07:42 PM

The Break Point at line 71 didn't show any differences.

Here is the display portion it was done in Blend

<Page
    x:Class="GeoSnapWindowsDesktop.MainPage"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:local="using:GeoSnapWindowsDesktop"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    mc:Ignorable="d">

    <Grid Background="Black">
    	<TextBlock HorizontalAlignment="Left" Margin="208,488,0,0" TextWrapping="Wrap" Text="Longitude:" VerticalAlignment="Top" FontSize="29.333" Width="146" Foreground="#FF40F717"/>
    	<TextBlock HorizontalAlignment="Left" Margin="208,566,0,0" TextWrapping="Wrap" Text="Latitude:" VerticalAlignment="Top" FontSize="29.333" Width="139" Foreground="#FF40F717"/>
    	<TextBlock HorizontalAlignment="Left" Margin="208,409,0,0" TextWrapping="Wrap" Text="GPS Status:" VerticalAlignment="Top" FontSize="29.333" Width="146" Foreground="#FF40F717"/>
    	<TextBox x:Name="Longitude" HorizontalAlignment="Left" Margin="375,491,0,0" TextWrapping="Wrap" Text="Longitude" VerticalAlignment="Top" Width="176"/>
    	<TextBox x:Name="Latitude" HorizontalAlignment="Left" Margin="375,566,0,0" TextWrapping="Wrap" Text="Latitude" VerticalAlignment="Top" Width="176"/>
    	<TextBox x:Name="GPS_Status" HorizontalAlignment="Left" Margin="375,412,0,0" TextWrapping="Wrap" Text="GPSStatus" VerticalAlignment="Top" Width="176"/>
    	<TextBlock HorizontalAlignment="Left" Height="42" Margin="714,491,0,0" TextWrapping="Wrap" Text="Patient ID:" VerticalAlignment="Top" Width="153" FontSize="29.333" SelectionHighlightColor="#FFB4A617" Foreground="#FF40F717"/>
    	<TextBlock HorizontalAlignment="Left" Margin="714,566,0,0" TextWrapping="Wrap" Text="Visit ID:" VerticalAlignment="Top" Height="42" Width="118" FontSize="29.333" SelectionHighlightColor="#FFB4A617" Foreground="#FF40F717"/>
    	<TextBox x:Name="PatinetID" HorizontalAlignment="Left" Margin="893,491,0,0" TextWrapping="Wrap" Text="PatientID" VerticalAlignment="Top" Width="212" InputScope="Number"/>
    	<TextBox x:Name="VisitID" HorizontalAlignment="Left" Margin="893,569,0,0" TextWrapping="Wrap" Text="VisitID" VerticalAlignment="Top" Width="212" InputScope="Number"/>
    	<Button x:Name="Submit" Content="Submit" HorizontalAlignment="Left" Margin="581,678,0,0" VerticalAlignment="Top" Width="218" FontSize="21.333" Background="#FFEED9D9" Foreground="#FF0A348F" />
    	<Viewbox HorizontalAlignment="Left" Height="100" Margin="304,375,0,0" VerticalAlignment="Top" Width="100"/>
    	<Button x:Name="Close" Content="Close" HorizontalAlignment="Left" Margin="1271,678,0,0" VerticalAlignment="Top" Foreground="#FFFB1111"  RenderTransformOrigin="0.451,-0.656" Height="47" FontSize="22"/>
    	<TextBlock HorizontalAlignment="Left" Margin="714,418,0,0" TextWrapping="Wrap" Text="Date:" VerticalAlignment="Top" FontSize="29.333" Width="139" Foreground="#FF40F717"/>
    	<TextBox x:Name="Date" HorizontalAlignment="Left" Margin="893,409,0,0" TextWrapping="Wrap" Text="Date" VerticalAlignment="Top" Width="212"/>
    	<GridView HorizontalAlignment="Left" Margin="10,10,0,0" VerticalAlignment="Top" Width="1356" Height="365">
    		<GridView.Foreground>
    			<SolidColorBrush Color="White" Opacity="0.9"/>
    		</GridView.Foreground>
    		<GridView.Background>
    			<ImageBrush Stretch="Fill" ImageSource="Assets/Background/Planet-earth.png"/>
    		</GridView.Background>
    		<TextBlock Height="255" TextWrapping="Wrap" Width="1342" FontSize="160" FontStyle="Italic">
    			<TextBlock.Foreground>
    				<LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
    					<GradientStop Color="Black" Offset="0"/>
    					<GradientStop Color="#FFF78C74" Offset="1"/>
    				</LinearGradientBrush>
    			</TextBlock.Foreground>
    			<Run Text="        "/>
    			<Run Text="GeoSnap">
    				<Run.Foreground>
    					<LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
    						<GradientStop Color="Black" Offset="0"/>
    						<GradientStop Color="#FF77F73B" Offset="1"/>
    					</LinearGradientBrush>
    				</Run.Foreground>
    			</Run>
    		</TextBlock>
    	</GridView>
    	<Button x:Name="EnableGPS" Content="Enable" HorizontalAlignment="Left" Margin="70,415,0,0" VerticalAlignment="Top"/>
    	<Button x:Name="DisableGPS" Content="Disable" HorizontalAlignment="Left" Margin="70,485,0,0" VerticalAlignment="Top"/>
    	<TextBlock HorizontalAlignment="Left" Margin="208,628,0,0" TextWrapping="Wrap" Text="Accuracy:" VerticalAlignment="Top" FontSize="29.333" RenderTransformOrigin="-0.17,0.351" Foreground="#FF40F717" Width="139"/>
    	<TextBox x:Name="Accuracy" HorizontalAlignment="Left" Margin="375,628,0,0" TextWrapping="Wrap" Text="Accuracy" VerticalAlignment="Top" Width="176"/>

    </Grid>
</Page>



Was This Post Helpful? 0
  • +
  • -

#4 Skydiver   User is online

  • Code herder
  • member icon

Reputation: 7457
  • View blog
  • Posts: 25,102
  • Joined: 05-May 12

Re: Geolocation no errors but does not work?

Posted 21 March 2014 - 07:54 PM

Does the breakpoint even get hit? If it does get hit, what happens when you press F10?
Was This Post Helpful? 0
  • +
  • -

#5 Momerath   User is offline

  • D.I.C Lover
  • member icon

Reputation: 1021
  • View blog
  • Posts: 2,463
  • Joined: 04-October 09

Re: Geolocation no errors but does not work?

Posted 21 March 2014 - 08:07 PM

View PostThomasHohner, on 21 March 2014 - 07:42 PM, said:

The Break Point at line 71 didn't show any differences.


What does that mean? Did you examine the pos variable and see what values are in it?
Was This Post Helpful? 0
  • +
  • -

#6 ThomasHohner   User is offline

  • New D.I.C Head

Reputation: 2
  • View blog
  • Posts: 15
  • Joined: 10-March 14

Re: Geolocation no errors but does not work?

Posted 22 March 2014 - 11:30 AM

My Apologies everyone, I figured it out I and it was in the display code. I forgot to put Click="EnableGPS_Click". I thought I had, but when I went back and double checked it wasn't there. How embarrassing! This is as bad as the time I wrote this lovely query in T-SQl and couldn't figure out why no results were generating. ( VisitDate BETWEEN @EndDate and @StartDate)I had this lil nugget in on that one.

Thanks for all of your help though.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1