Exemplo n.º 1
0
        private void AddPushpin(string deviceID, Windows.Devices.Geolocation.BasicGeoposition position)
        {
            var mapDevices = new List <MapElement>();

            Windows.Devices.Geolocation.BasicGeoposition snPosition = new Windows.Devices.Geolocation.BasicGeoposition {
                Latitude = position.Latitude, Longitude = position.Longitude
            };

            var pushpin = new MapIcon
            {
                Location = new Geopoint(snPosition),
                NormalizedAnchorPoint = new Point(0.5, 1),
                ZIndex = 1000,
                Tag    = "NEW",
                Title  = deviceID,
                Image  = RandomAccessStreamReference.CreateFromUri(new Uri(resourceLoader.GetString("Map_Pushpin_New"))),
            };

            mapDevices.Add(pushpin);

            var mapDevicesLayer = new MapElementsLayer
            {
                ZIndex      = 1,
                MapElements = mapDevices
            };

            MapLayers.Add(mapDevicesLayer);
            CTRL_Map_Main.Layers.Add(mapDevicesLayer);
        }
Exemplo n.º 2
0
		/// <summary>
		/// Invoked when this page is about to be displayed in a Frame.
		/// </summary>
		/// <param name="e">Event data that describes how this page was reached.
		/// This parameter is typically used to configure the page.</param>
		protected async override void OnNavigatedTo(NavigationEventArgs e)
		{
			Geopoint myPoint;

			if (e.Parameter == null)
			{
				//Add
				isViewing = false;

				var locator = new Geolocator();
				locator.DesiredAccuracyInMeters = 50;

				// MUST ENABLE THE LOCATION CAPABILITY!!
				var position = await locator.GetGeopositionAsync();
				myPoint = position.Coordinate.Point;
			}
			else
			{
				//View or Delete
				isViewing = true;

				lifeThread = (LifeThread)e.Parameter;
				titleTextBox.Text = lifeThread.Title;
				noteTextBox.Text = lifeThread.Thread;
				addButton.Content = "Delete";

				var myPosition = new Windows.Devices.Geolocation.BasicGeoposition();
				myPosition.Latitude = lifeThread.Latitude;
				myPosition.Longitude = lifeThread.Longitude;

				myPoint = new Geopoint(myPosition);
			}

			await MyMap.TrySetViewAsync(myPoint, 16d);
		}
Exemplo n.º 3
0
        /// <summary>
        /// Invoked when this page is about to be displayed in a Frame.
        /// </summary>
        /// <param name="e">Event data that describes how this page was reached.
        /// This parameter is typically used to configure the page.</param>
        protected async override void OnNavigatedTo(NavigationEventArgs e)
        {
            Geopoint mypoint;

            if (e.Parameter == null)
            {
                // this is when the user is adding
                isViewing = false;
                var locator = new Geolocator();
                locator.DesiredAccuracyInMeters = 50;

                var position = await locator.GetGeopositionAsync();

                mypoint = position.Coordinate.Point;
            }
            else
            {
                // when the user is viewing/ deleting
                isViewing         = true;
                myNote            = (Note)e.Parameter;
                titleTextBox.Text = myNote.Title;
                noteTextBox.Text  = myNote.Notes;
                addButton.Content = "Delete";

                var myPosition = new Windows.Devices.Geolocation.BasicGeoposition();
                myPosition.Latitude  = myNote.Latitude;
                myPosition.Longitude = myNote.Longitude;

                mypoint = new Geopoint(myPosition);
            }
            await MyMap.TrySetViewAsync(mypoint, 19D);
        }
Exemplo n.º 4
0
        protected async override void OnNavigatedTo(NavigationEventArgs e)
        {
            Geopoint mypoint;

            if (e.Parameter == null)
            {
                // this is when the user is adding
                isViewing = false;
                var locator = new Geolocator();
                locator.DesiredAccuracyInMeters = 50;
                var position = await locator.GetGeopositionAsync();

                mypoint = position.Coordinate.Point;
            }
            else
            {
                // when the user is viewing/ deleting
                isViewing         = true;
                myNote            = (Note)e.Parameter;
                lblHeading.Text   = "Edit Note";
                titleTextBox.Text = myNote.Title;
                noteTextBox.Text  = myNote.Content;
                // dynamic changing of teh ui controls.
                addcommandbar.Content = "Delete";
                addcommandbar.Icon    = new SymbolIcon(Symbol.Delete);
                // retrieve the position where the note was stored and display it on the map control
                var myPosition = new Windows.Devices.Geolocation.BasicGeoposition();
                myPosition.Latitude  = myNote.Latitude;
                myPosition.Longitude = myNote.Longitude;
                mypoint = new Geopoint(myPosition);
            }
            await MyMap.TrySetViewAsync(mypoint, 19D);
        }
Exemplo n.º 5
0
        private async void setPositionButton_Click(object sender, RoutedEventArgs e)
        {
          var myPosition = new Windows.Devices.Geolocation.BasicGeoposition();
          myPosition.Latitude = 41.7446;
          myPosition.Longitude = -087.7915;

          var myPoint = new Windows.Devices.Geolocation.Geopoint(myPosition);
          if (await MyMap.TrySetViewAsync(myPoint, 10D))
          {
            // Haven't really thought that through!
          }

        }
Exemplo n.º 6
0
        private async void setPositionButton_Click(object sender, RoutedEventArgs e)
        {
            var myPosition = new Windows.Devices.Geolocation.BasicGeoposition();

            myPosition.Latitude  = 50.9652;
            myPosition.Longitude = 005.4951;

            var myPoint = new Windows.Devices.Geolocation.Geopoint(myPosition);

            if (await MyMap.TrySetViewAsync(myPoint, 10D))
            {
            }
        }
        private async void phoneButton_Click(object sender, RoutedEventArgs e)
        {
            var myPosition = new Windows.Devices.Geolocation.BasicGeoposition();

            myPosition.Latitude  = 33.845;
            myPosition.Longitude = -118.38;

            var myPoint = new Windows.Devices.Geolocation.Geopoint(myPosition);

            if (await locatorMap.TrySetViewAsync(myPoint, 10D))
            {
                // Haven't really thought that through!
            }
        }
Exemplo n.º 8
0
        //private async  void AddNote_Loaded(object setter, NavigationEventArgs e)
        protected async override void OnNavigatedTo(NavigationEventArgs e)
        {
            //map service token from bing maps
            Map.MapServiceToken = "TOfdeDRJwGImuiaL7W88~SlMn6bqFU6GCmOupV2lB-g~AsoKvGZZisSkTudn4cs2nwQzmGl7eS58HojnUjiskKBwBEYkH-7yUV7sRAXsADIr";
            //set map style for add note feature.
            Map.Style = MapStyle.AerialWithRoads;
            Geopoint pos;

            if (e.Parameter == null)
            {
                viewing = false;

                var location = new Geolocator();
                location.DesiredAccuracyInMeters = 50;
                var position = await location.GetGeopositionAsync();

                pos = position.Coordinate.Point;
            }
            else
            {
                viewing = true;

                myText            = (MyMapNote)e.Parameter;
                titleTextBox.Text = myText.Title;
                noteTextBox.Text  = myText.Note;
                //if viewing =true then we are in the delete mode
                // and add button content will change to delete
                // and the function will change to a delete function
                addBtn.Content = "Delete";

                var myPos = new Windows.Devices.Geolocation.BasicGeoposition();
                myPos.Latitude  = myText.Latitude;
                myPos.Longitude = myText.Longitude;

                //drop a ancor pin to mark center point
                pos = new Geopoint(myPos);
                MapIcon icon = new MapIcon();
                icon.Location = pos;
                icon.NormalizedAnchorPoint = new Point(0.5, 1.0);
                icon.Title  = "Note Location";
                icon.Image  = RandomAccessStreamReference.CreateFromUri(new Uri("ms-appx:///Assets/Pin.png"));
                icon.ZIndex = 0;
                Map.MapElements.Add(icon);
                Map.Center = pos;
            }

            await Map.TrySetViewAsync(pos, 14D);
        }
Exemplo n.º 9
0
        /// <summary>
        /// Invoked when this page is about to be displayed in a Frame.
        /// </summary>
        /// <param name="e">Event data that describes how this page was reached.
        /// This parameter is typically used to configure the page.</param>
        protected async override void OnNavigatedTo(NavigationEventArgs e)
        {
            MyMap.Style = Windows.UI.Xaml.Controls.Maps.MapStyle.Aerial;
            var golfCourse = new Windows.Devices.Geolocation.BasicGeoposition();

            golfCourse.Latitude  = 35.851182;
            golfCourse.Longitude = -86.413273;

            var mypos = new Windows.Devices.Geolocation.Geopoint(golfCourse);

            if (await MyMap.TrySetViewAsync(mypos, 15D))
            {
                ;
            }
            mySlider.Value = MyMap.ZoomLevel;
        }
Exemplo n.º 10
0
        /// <summary>
        /// Adds box around the currently selected map.
        /// </summary>
        private void AddBoxToMap()
        {
            List <BasicGeoposition> list = new List <BasicGeoposition>();

            BasicGeoposition topLeft = new BasicGeoposition
            {
                Longitude = BoundTopLeft.Longitude,
                Latitude  = BoundTopLeft.Latitude
            };

            list.Add(topLeft);

            BasicGeoposition topRight = new BasicGeoposition
            {
                Longitude = BoundBottomRight.Longitude,
                Latitude  = BoundTopLeft.Latitude
            };

            list.Add(topRight);

            BasicGeoposition bottomRight = new BasicGeoposition
            {
                Longitude = BoundBottomRight.Longitude,
                Latitude  = BoundBottomRight.Latitude
            };

            list.Add(bottomRight);

            BasicGeoposition bottomLeft = new BasicGeoposition
            {
                Longitude = BoundTopLeft.Longitude,
                Latitude  = BoundBottomRight.Latitude
            };

            list.Add(bottomLeft);

            MapPolygon boundaryPolygon = new MapPolygon
            {
                Path      = new Geopath(list),
                FillColor = Color.FromArgb(25, 50, 50, 50)
            };

            MyMapControl.MapElements.Add(boundaryPolygon);
        }
Exemplo n.º 11
0
        private async void backpackButton_Click(object sender, RoutedEventArgs e)
        {
            if (saved_locations.Values.ContainsKey("backpack-location-latitude") && saved_locations.Values.ContainsKey("backpack-location-longitude"))
            {
                double lat = Convert.ToDouble(saved_locations.Values["backpack-location-latitude"].ToString());
                double lon = Convert.ToDouble(saved_locations.Values["backpack-location-longitude"].ToString());

                BasicGeoposition myPosition = new Windows.Devices.Geolocation.BasicGeoposition();
                myPosition.Latitude  = lat;
                myPosition.Longitude = lon;

                Geopoint myPoint = new Windows.Devices.Geolocation.Geopoint(myPosition);
                await locatorMap.TrySetViewAsync(myPoint, 10D);
            }
            else
            {
                positionTextBlock.Text = "No Location Saved!";
            }
        }
Exemplo n.º 12
0
        protected async override void OnNavigatedTo(NavigationEventArgs e)
        {
            Geopoint myPoint;

            if ((e.Parameter as Geopoint) != null)
            {
                System.Diagnostics.Debug.WriteLine("This is a geopoint");
                Save.Content = "Add";
                //isViewing = true;
                mapNote = new Andmed();
                myPoint = (e.Parameter as Geopoint);
            }
            else if (e.Parameter == null)
            {
                System.Diagnostics.Debug.WriteLine((e.Parameter as Geopoint) != null);
                //isViewing = false;

                var locator = new Geolocator();
                locator.DesiredAccuracyInMeters = 50;

                var position = await locator.GetGeopositionAsync();

                myPoint = position.Coordinate.Point;
            }

            else
            {
                Save.Content = "Remove";
                //isViewing = true;
                mapNote           = (Andmed)e.Parameter;
                titleTextBox.Text = mapNote.Nimi;
                noteTextBox.Text  = mapNote.Text;
                var myPosition = new Windows.Devices.Geolocation.BasicGeoposition();

                myPosition.Latitude  = mapNote.Ver;
                myPosition.Longitude = mapNote.Hor;

                myPoint = new Geopoint(myPosition);
            }
            await MyMap.TrySetViewAsync(myPoint, 16D);
        }
Exemplo n.º 13
0
        private async void setPositionButton_Click(object sender, RoutedEventArgs e)
        {
            Geolocator geolocator = new Geolocator();

            if (geolocator.LocationStatus == PositionStatus.Disabled)
            {
                MessageDialog msgbox = new MessageDialog("Turn GPS ON", "ERROR");
                await msgbox.ShowAsync();

                return;
            }

            geolocator.DesiredAccuracyInMeters = 50;

            //Get the gps coordinates of current location
            try
            {
                Geoposition geoposition = await geolocator.GetGeopositionAsync(
                    maximumAge : TimeSpan.FromMinutes(5),
                    timeout : TimeSpan.FromSeconds(10)
                    );

                var myPosition = new Windows.Devices.Geolocation.BasicGeoposition();
                myPosition.Latitude  = geoposition.Coordinate.Latitude;
                myPosition.Longitude = geoposition.Coordinate.Longitude;

                var myPoint = new Windows.Devices.Geolocation.Geopoint(myPosition);
                if (await MyMap.TrySetViewAsync(myPoint, 10D))
                {
                    // Haven't really thought that through!
                }
            }
            catch (Exception ex)
            {
                Debug.WriteLine(ex);
            }
        }
Exemplo n.º 14
0
        private async void setPositionButton_Click(object sender, RoutedEventArgs e)
        {
            Geolocator geolocator = new Geolocator();
            if (geolocator.LocationStatus == PositionStatus.Disabled) {
                MessageDialog msgbox = new MessageDialog("Turn GPS ON", "ERROR");
                await msgbox.ShowAsync();
                return;
            }

            geolocator.DesiredAccuracyInMeters = 50;
           
            //Get the gps coordinates of current location
            try
            {
                Geoposition geoposition = await geolocator.GetGeopositionAsync(
                     maximumAge: TimeSpan.FromMinutes(5),
                     timeout: TimeSpan.FromSeconds(10)
                    );

                var myPosition = new Windows.Devices.Geolocation.BasicGeoposition();
                myPosition.Latitude = geoposition.Coordinate.Latitude;
                myPosition.Longitude = geoposition.Coordinate.Longitude;

                var myPoint = new Windows.Devices.Geolocation.Geopoint(myPosition);
                if (await MyMap.TrySetViewAsync(myPoint, 10D))
                {
                    // Haven't really thought that through!
                }
            }
            catch (Exception ex)
            {
                Debug.WriteLine(ex);
            }        

            
        }
Exemplo n.º 15
0
        private async void Hole2_Click(object sender, RoutedEventArgs e)
        {
            var hole_3 = new Windows.Devices.Geolocation.BasicGeoposition();

            hole_3.Latitude  = 35.847709;
            hole_3.Longitude = -86.414191;
            MyMap.Heading    = 358;
            var mypos = new Windows.Devices.Geolocation.Geopoint(hole_3);

            if (await MyMap.TrySetViewAsync(mypos, 17.5D))
            {
                ;
            }
            mySlider.Value = MyMap.ZoomLevel;
            var location = new Geolocator();

            location.DesiredAccuracyInMeters = 1;
            var position = await location.GetGeopositionAsync();

            double lat      = (position.Coordinate.Latitude) * Math.PI / 180;
            double longi    = (position.Coordinate.Longitude) * Math.PI / 180;
            double latB     = (hole_3.Latitude) * Math.PI / 180;
            double LongiB   = (hole_3.Longitude) * Math.PI / 180;
            double latEND   = (lat - latB);
            double longiEND = (longi - LongiB);
            double x        = Math.Cos(lat) * Math.Sin(latB) - Math.Sin(lat) * Math.Cos(latB) * Math.Cos(longiEND);
            double y        = Math.Sin(longiEND) * Math.Cos(latB);
            double hdg      = 0;

            if (y > 0)
            {
                if (x > 0)
                {
                    hdg = Math.Atan(y / x);
                }
                if (x < 0)
                {
                    hdg = 180 - Math.Atan(-y / x);
                }
                if (x == 0)
                {
                    hdg = 90;
                }
            }
            if (y < 0)
            {
                if (x > 0)
                {
                    hdg = -Math.Atan(-y / x);
                }
                if (x < 0)
                {
                    hdg = Math.Atan(y / x) - 180;
                }
                if (x == 0)
                {
                    hdg = 270;
                }
            }
            if (y == 0)
            {
                if (x > 0)
                {
                    hdg = 0;
                }
                if (x < 0)
                {
                    hdg = 180;
                }
            }
            hdg = Convert.ToInt32(hdg * 180 / Math.PI) % 360;
            positionTextBlock.Text = String.Format("{0}, {1}",
                                                   MyMap.Center.Position.Latitude,
                                                   MyMap.Center.Position.Longitude);
            double dest = 0;

            dest = (Math.Sin((latB - lat) / 2) * Math.Sin((latB - lat) / 2)) + (Math.Cos(lat) * Math.Cos(latB) * Math.Sin((LongiB - longi) / 2) * Math.Sin((LongiB - longi) / 2));
            dest = 2 * Math.Atan2(Math.Sqrt(dest), Math.Sqrt(1 - dest));
            dest = dest * 63710000;
            dest = Convert.ToInt32(dest * 1.09361);
            positionTextBlock.Text = "Current place: " + position.Coordinate.Latitude.ToString() + " " + position.Coordinate.Longitude.ToString() + "\nTo hole: " +
                                     hdg.ToString() + " degrees, " + dest.ToString() + " yards.";
        }
Exemplo n.º 16
0
        public void AddNewDevice(string deviceID, Windows.Devices.Geolocation.BasicGeoposition position)
        {
            NewDevices.Add(new Device(deviceID, position));

            TB_NewDevices.Text = NewDevices.Count.ToString(CultureInfo.InvariantCulture);
        }
Exemplo n.º 17
0
 public Geopoint(BasicGeoposition position)
 {
     Position = position;
 }
Exemplo n.º 18
0
 public Geopoint(BasicGeoposition position, AltitudeReferenceSystem altitudeReferenceSystem, uint spatialReferenceId) : this(position, altitudeReferenceSystem)
 {
     SpatialReferenceId = spatialReferenceId;
 }
Exemplo n.º 19
0
        async protected override void OnNavigatedTo(NavigationEventArgs e)
        {
            double latitude  = 53.2740967;
            double longitude = -9.0495774;

            try
            {
                // Request permission to access location
                var accessStatus = await Geolocator.RequestAccessAsync();

                Geoposition pos = null;

                switch (accessStatus)
                {
                case GeolocationAccessStatus.Allowed:

                    // Get cancellation token
                    _cts = new CancellationTokenSource();
                    CancellationToken token = _cts.Token;

                    //_rootPage.NotifyUser("Waiting for update...", NotifyType.StatusMessage);

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

                    // Carry out the operation
                    pos = await geolocator.GetGeopositionAsync().AsTask(token);

                    latitude  = pos.Coordinate.Latitude;
                    longitude = pos.Coordinate.Longitude;



                    // UpdateLocationData(pos);
                    //   _rootPage.NotifyUser("Location updated.", NotifyType.StatusMessage);
                    break;

                case GeolocationAccessStatus.Denied:

                    break;

                case GeolocationAccessStatus.Unspecified:

                    break;
                }
            }
            catch (TaskCanceledException)
            {
                // _rootPage.NotifyUser("Canceled.", NotifyType.StatusMessage);
            }
            catch (Exception ex)
            {
                // _rootPage.NotifyUser(ex.ToString(), NotifyType.ErrorMessage);
            }
            finally
            {
                _cts = null;
            }

            HyperLink1.Content = String.Format("Lat= {0:N3},Long= {1:N3}", latitude, longitude);

            // Specify a known location.
            Windows.Devices.Geolocation.BasicGeoposition cityPosition = new Windows.Devices.Geolocation.BasicGeoposition()
            {
                Latitude = latitude, Longitude = longitude
            };
            Windows.Devices.Geolocation.Geopoint cityCenter = new Windows.Devices.Geolocation.Geopoint(cityPosition);

            // Set the map location.
            MapControl1.Center           = cityCenter;
            MapControl1.ZoomLevel        = 12;
            MapControl1.LandmarksVisible = true;
        }
Exemplo n.º 20
0
 public Geopoint(BasicGeoposition position, AltitudeReferenceSystem altitudeReferenceSystem) : this(position)
 {
     AltitudeReferenceSystem = altitudeReferenceSystem;
 }