async void ChangedEventHandler(object sender, GeoEventArgs e)
        {
            if (!mLocSet)
            {
                CoreDispatcher disp = CoreApplication.MainView.CoreWindow.Dispatcher;

                double dlat = e.Lat;
                double dlon = e.Lon;

                await disp.RunAsync(CoreDispatcherPriority.Normal, () => { rbNorth.IsChecked = dlat > 0;
                                                                           rbSouth.IsChecked = dlat < 0;
                                                                           rbEast.IsChecked  = dlon > 0;
                                                                           rbWest.IsChecked  = dlon < 0;
                                                                           tbWait.Visibility = Visibility.Collapsed; });

                await disp.RunAsync(CoreDispatcherPriority.Normal, () => { ResetMapPositions(dlat, dlon); });

                await CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPriority.Normal,
                                                                              () =>
                {
                    tbCurCoords.Text = GPSConverter.ConvertDeg2DegMinutes(dlat) + "," + GPSConverter.ConvertDeg2DegMinutes(dlon);
                    IsEnabled        = true;
                });

                mLocSet = true;
            }
        }
        private async void btnConvert_Click(object sender, RoutedEventArgs e)
        {
            string coords = tbCoords.Text;

            if (cbCoords.SelectedIndex == 0)
            {
                string[] fields = coords.Split(',');

                string slat = fields[0];
                string slon = fields[1];
            }
            else if (cbCoords.SelectedIndex == 1)
            {
                string[] fields = coords.Split(',');

                if (fields.Length == 2)
                {
                    string[] latFields = fields[0].Split(' ');
                    string[] lonFields = fields[1].Split(' ');

                    int lon, lat;

                    if (int.TryParse(fields[0], out lat) && int.TryParse(fields[1], out lon))
                    {
                        GPSConverter c = new GPSConverter();

                        double newLat = c.toLat(lat, lon);
                        double newLon = c.toLon(lat, lon);

                        mMsgDlg.Content = (newLat < 0 ? "S" : "N") + GPSConverter.ConvertDeg2DegMinutes(newLat) +
                                          (newLon < 0 ? " W" : " E") + GPSConverter.ConvertDeg2DegMinutes(newLon);
                        await mMsgDlg.ShowAsync();

                        GeoLocation.SetMapPosition(mapControl, newLat, newLon, mMsgDlg.Content, 15);
                    }
                    else
                    {
                        mMsgDlg.Content = "Incorrect Dutch Grid format. It must be of the form xxxxx,yyyyyy";
                        await mMsgDlg.ShowAsync();
                    }
                }
                else
                {
                    mMsgDlg.Content = "Incorrect Dutch Grid format. It must be of the form xxxxx,yyyyyy";
                    await mMsgDlg.ShowAsync();
                }
            }
            else
            {
                mMsgDlg.Content = coords;
                await mMsgDlg.ShowAsync();
            }
        }
        private async void btnProject_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                Geolocator geolocator = new Geolocator {
                    DesiredAccuracyInMeters = 10
                };

                Geoposition pos = await geolocator.GetGeopositionAsync();

                double dlat = pos.Coordinate.Point.Position.Latitude;
                double dlon = pos.Coordinate.Point.Position.Longitude;

                ResetMapPositions(dlat, dlon);

                if (cbCoords.SelectedIndex == 0)
                {
                    string[] fields = tbCoords.Text.Split(',');

                    if (fields.Length == 2)
                    {
                        string[] latCoords = fields[0].Trim(' ').Split(' ');
                        string[] lonCoords = fields[1].Trim(' ').Split(' ');

                        double lat, lon;

                        lat = double.Parse(latCoords[0]) + (double.Parse(latCoords[1]) / 60);
                        lon = double.Parse(lonCoords[0]) + (double.Parse(lonCoords[1]) / 60);

                        double newLon, newLat;

                        int angle, meters;

                        if (!int.TryParse(tbProjectAngle.Text, out angle))
                        {
                            mMsgDlg.Content = "Please enter an angle in the angle box on the left";
                            await mMsgDlg.ShowAsync();

                            return;
                        }
                        if (!int.TryParse(tbProjectMeters.Text, out meters))
                        {
                            mMsgDlg.Content = "Please enter the distance in the distance box on the right";
                            await mMsgDlg.ShowAsync();

                            return;
                        }

                        if (cbMeters.SelectedIndex == 1)
                        {
                            meters *= 1000;
                        }
                        else if (cbMeters.SelectedIndex == 2)
                        {
                            meters = (int)Math.Round(meters * 1609.344);
                        }

                        GPSConverter.Project(lon, lat, angle, meters, out newLon, out newLat);

                        mMsgDlg.Content = newLat.ToString("00.00000") + " " + newLon.ToString("000.00000") + "\n" +
                                          GPSConverter.ConvertDeg2DegMinutes(newLat) + " " + GPSConverter.ConvertDeg2DegMinutes(newLon);
                        await mMsgDlg.ShowAsync();

                        SetMapPosition(newLat, newLon, "Projected", 15);
                    }
                    else
                    {
                        mMsgDlg.Content = "Latitude and longitude must be separated by a comma";
                        await mMsgDlg.ShowAsync();
                    }
                }
                else if (cbCoords.SelectedIndex == 1)
                {
                    string[] fields = tbCoords.Text.Split(',');

                    if (fields.Length == 2)
                    {
                        int angle, meters;

                        if (!int.TryParse(tbProjectAngle.Text, out angle))
                        {
                            mMsgDlg.Content = "Please enter an angle in the angle box on the left";
                            await mMsgDlg.ShowAsync();

                            return;
                        }
                        if (!int.TryParse(tbProjectMeters.Text, out meters))
                        {
                            mMsgDlg.Content = "Please enter the distance in the distance box on the right";
                            await mMsgDlg.ShowAsync();

                            return;
                        }

                        double lat = double.Parse(fields[0].Trim());
                        double lon = double.Parse(fields[1].Trim());

                        if (cbMeters.SelectedIndex == 1)
                        {
                            meters *= 1000;
                        }

                        double newLat, newLon;

                        GPSConverter.Project(lon, lat, angle, meters, out newLon, out newLat);

                        mMsgDlg.Content = newLat.ToString("00.00000") + " " + newLon.ToString("000.00000") + "\n" +
                                          GPSConverter.ConvertDeg2DegMinutes(newLat) + " " + GPSConverter.ConvertDeg2DegMinutes(newLon);
                        await mMsgDlg.ShowAsync();

                        SetMapPosition(newLat, newLon, "Projected", 15);
                    }
                    else
                    {
                        mMsgDlg.Content = "Latitude and longitude must be separated by a comma";
                        await mMsgDlg.ShowAsync();
                    }
                }
                else
                {
                    mMsgDlg.Content = "Only Degrees and Degrees Minutes projection is implemented.";
                    await mMsgDlg.ShowAsync();
                }
            }
            finally
            {
                tbProjectAngle.Text  = "Deg";
                tbProjectMeters.Text = "Dst";
            }
        }