Esempio n. 1
0
        void SetUserTrackCurrentLocation(double latitude, double longitude)
        {
            try
            {
                if (btnTrack.Content.Equals("➤"))
                {
                    return;
                }

                foreach (var children in trvMap.Children)
                {
                    if (children.GetType().Name == "LocationIcon10m")
                    {
                        trvMap.Children.Remove(children);
                        break;
                    }
                }
                // Get the cancellation token.
                _cts  = new CancellationTokenSource();
                token = _cts.Token;
                // Get the location.

                CloseMessage();
                System.Device.Location.GeoCoordinate location = new System.Device.Location.GeoCoordinate(latitude, longitude);

                // Now set the zoom level of the map based on the accuracy of our location data.
                // Default to IP level accuracy. We only show the region at this level - No icon is displayed.
                double          zoomLevel            = 17.0f;
                LocationIcon10m _locationUserIcon10m = new LocationIcon10m();
                Callout         callout = new Callout();

                callout.Text = "Tracker's Location";
                callout.Lon  = "Lon (λ): " + location.Longitude.ToString().Substring(0, 7);;
                callout.Lat  = "Lat (φ): " + location.Latitude.ToString().Substring(0, 7);;
                _locationUserIcon10m.DataContext = callout;
                // Add the 10m icon and zoom closer.
                trvMap.Children.Add(_locationUserIcon10m);
                MapLayer.SetPosition(_locationUserIcon10m, location);
                // Set the map to the given location and zoom level.
                trvMap.SetView(location, zoomLevel);
            }
            catch { }
        }
Esempio n. 2
0
        async void SetCurrentLocation()
        {
            try
            {
                if (!btnTrack.Content.Equals("➤"))
                {
                    return;
                }

                foreach (var children in trvMap.Children)
                {
                    if (children.GetType().Name == "LocationIcon100m")
                    {
                        trvMap.Children.Remove(children);
                        break;
                    }
                }

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

                var asyncResult = _geolocator.GetGeopositionAsync();
                var task        = asyncResult.AsTask();

                var readyTask = await Task.WhenAny(task, Task.Delay(10000));

                if (readyTask != task)
                {
                    SetMessage(MessageType.Error, "❎ Unable to find your location, trying again...");
                    SetCurrentLocation();
                }

                Geoposition pos = await task;
                //Geoposition pos = await _geolocator.GetGeopositionAsync().AsTask(token);
                //  MessageTextbox.Text = "";

                System.Device.Location.GeoCoordinate location = new System.Device.Location.GeoCoordinate(pos.Coordinate.Latitude, pos.Coordinate.Longitude);
                ProxyTracker.GetInstance().MyTrackLocation    = new Services.TrackService.TrackLocation {
                    Latitude = pos.Coordinate.Latitude, Longitude = pos.Coordinate.Longitude
                };

                // Now set the zoom level of the map based on the accuracy of our location data.
                // Default to IP level accuracy. We only show the region at this level - No icon is displayed.
                double zoomLevel = 13.0f;

                //// if we have GPS level accuracy
                Callout callout = new Callout();

                callout.Text = "My Location";
                callout.Lon  = "Lon (λ): " + location.Longitude.ToString().Substring(0, 7);
                callout.Lat  = "Lat (φ): " + location.Latitude.ToString().Substring(0, 7);
                _locationIcon100m.DataContext = callout;
                // Add the 100m icon and zoom a little closer.
                trvMap.Children.Add(_locationIcon100m);

                MapLayer.SetPosition(_locationIcon100m, location);
                zoomLevel = 17.0f;

                // Set the map to the given location and zoom level.
                trvMap.SetView(location, zoomLevel);

                try
                {
                    ProxyTracker.GetInstance().Client.StartTrackingCompleted += Client_StartTrackingCompleted;
                    ProxyTracker.GetInstance().Client.StartTrackingAsync(ProxyTracker.GetInstance().GetDeviceId(), ProxyTracker.GetInstance().MyTrackLocation);
                }
                catch (Exception ex) { MapCurrentLocation(); }
            }
            catch { }
        }