/// <summary> /// Listener for taps (clicks) on the map. /// </summary> /// <param name="sender">Event sender</param> /// <param name="args">Event arguments</param> private void OnTapMap(object sender, MapInputEventArgs args) { Geopoint tapped = args.Location; FitPoint(tapped); UpdateSelectionVisual(); }
private async void Timer_Tick(object sender, object e) { try { var responseVehicleStatus = new HttpClient().GetAsync(new Uri(_endpoint + "/api/vehicles/UAK298/status")).Result; if (responseVehicleStatus.IsSuccessStatusCode) { var vehicleStatus = JsonConvert.DeserializeObject <VehicleStatus>(await responseVehicleStatus.Content.ReadAsStringAsync()); var newPosition = new Windows.Devices.Geolocation.Geopoint(new Windows.Devices.Geolocation.BasicGeoposition() { Latitude = vehicleStatus.Latitude, Longitude = vehicleStatus.Longitude }); //mapControl.Center = position; _currentPosition.Location = newPosition; } var responseRuleStatus = new HttpClient().GetAsync(new Uri(_endpoint + "/api/vehicles/UAK298/rulestatus")).Result; if (responseRuleStatus.IsSuccessStatusCode) { var ruleStatusJson = JsonConvert.DeserializeObject <bool?>(await responseRuleStatus.Content.ReadAsStringAsync()); ruleStatus.Text = (!ruleStatusJson.HasValue ? "UNKNOWN" : ruleStatusJson.Value ? "INSIDE" : "OUTSIDE"); ruleStatus.Foreground = (!ruleStatusJson.HasValue ? new SolidColorBrush(Colors.Yellow) : ruleStatusJson.Value ? new SolidColorBrush(Colors.Green) : new SolidColorBrush(Colors.Red)); } } catch (Exception) { } }
/// <summary> /// Zooms map to current selection. /// </summary> private void ZoomToSelection() { // Get dictionary of bounds from API IDictionary <string, PostGisPoint> bounds = new ApiHandler.ApiHandler().GetBounds().ToDictionary(pair => pair.Key, pair => pair.Value); // Ensure that bounds exist if (!bounds.TryGetValue("top_left", out PostGisPoint topLeft) || !bounds.TryGetValue("bottom_right", out PostGisPoint botRight)) { // TODO : Add some sort of error return; } BoundTopLeft = topLeft; BoundBottomRight = botRight; // Calculate the center point Geopoint centerGeopoint = new Geopoint(new BasicGeoposition { Latitude = ((BoundTopLeft.Latitude - BoundBottomRight.Latitude) / 2) + BoundBottomRight.Latitude, Longitude = ((BoundBottomRight.Longitude - BoundTopLeft.Longitude) / 2) + BoundTopLeft.Longitude }); // Set viewport to bounds MyMapControl.TrySetViewAsync(centerGeopoint, 16); }
/// <summary> /// Listener for taps (clicks) on the map. /// </summary> /// <param name="sender">Event sender</param> /// <param name="args">Event arguments</param> private void OnTapMap(object sender, MapInputEventArgs args) { Geopoint tapped = args.Location; UpdateSelectionVisual(tapped); LabelPoint.Content = tapped.Position.Longitude + " " + tapped.Position.Latitude; }
/// <summary> /// Displays the currently selected area to the user, as well as any selected point. /// </summary> private void UpdateSelectionVisual(Geopoint point = null) { // Clear any current pins MyMapControl.MapElements.Clear(); // Redraw box around map selection AddBoxToMap(); // Check if point is actually specified if (point == null) { // Point was not specified, so clear everything ModelPath = string.Empty; LabelPoint.Content = Application.Current.FindResource("LabelNoPointSelected"); LabelModel.Content = Application.Current.FindResource("LabelNoModelSelected"); ButtonSelectModel.IsEnabled = false; } else { // Point was specified, so add it to the map and enable fields MapIcon pin = new MapIcon { Location = point }; MyMapControl.MapElements.Add(pin); ButtonSelectModel.IsEnabled = true; } // Keep track of the point ModelLocation = point; }
/// <summary> /// Zooms map to current selection. /// </summary> private void ZoomToSelection() { // Calculate the center point Geopoint centerGeopoint = new Geopoint(new BasicGeoposition { Latitude = 43.1927816, Longitude = -80.3851837 }); // Set viewport to bounds MyMapControl.TrySetViewAsync(centerGeopoint, 16); }
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! } }
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! } }
/// <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; }
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!"; } }
protected override void OnNavigatedTo(NavigationEventArgs e) { var position = new Windows.Devices.Geolocation.Geopoint(new Windows.Devices.Geolocation.BasicGeoposition() { Latitude = 57.693826, Longitude = 11.891392 }); base.OnNavigatedTo(e); mapControl.Center = position; mapControl.ZoomLevel = 14; _currentPosition = new MapIcon { Location = position, Title = "Current Position", ZIndex = 0 }; mapControl.MapElements.Add(_currentPosition); var points = ParseGeoBoundaryJson(_geoBoundaryJson); var polygon = new MapPolygon(); polygon.FillColor = Colors.Transparent; polygon.StrokeColor = Colors.Green; polygon.StrokeThickness = 5; var pathPositions = new List <BasicGeoposition>(); foreach (var point in points) { pathPositions.Add(new BasicGeoposition() { Latitude = point.Latitude, Longitude = point.Longitude }); } polygon.Paths.Add(new Geopath(pathPositions)); mapControl.MapElements.Add(polygon); var timer = new DispatcherTimer(); timer.Interval = TimeSpan.FromSeconds(2); timer.Tick += Timer_Tick; timer.Start(); }
/// <summary> /// Updates the selection bounds to fit the specified point. /// </summary> /// <param name="point">The point to fit within the bounds</param> private void FitPoint(Geopoint point) { // Check if selection has been initialized if (mLeft >= 300) { // Selection has not been started, so all dimensions are the same mLeft = point.Position.Longitude; mRight = point.Position.Longitude; mTop = point.Position.Latitude; mBottom = point.Position.Latitude; return; } // Update left bound if needed if ((mLeft + 180) > (point.Position.Longitude + 180)) { mLeft = point.Position.Longitude; } // Update right bound if needed if ((mRight + 180) < (point.Position.Longitude + 180)) { mRight = point.Position.Longitude; } // Update top bound if needed if ((mTop + 90) < (point.Position.Latitude + 90)) { mTop = point.Position.Latitude; } // Update bottom bound if needed if ((mBottom + 90) > (point.Position.Latitude + 90)) { mBottom = point.Position.Latitude; } }
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); } }
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); } }
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; }
public async void getDestination() { Windows.Devices.Geolocation.Geopoint point = new Windows.Devices.Geolocation.Geopoint(new Windows.Devices.Geolocation.BasicGeoposition() { Latitude = 51.58914, Longitude = 4.74304 }); MapLocationFinderResult result = await Windows.Services.Maps.MapLocationFinder.FindLocationsAsync("Niewegein,Blokhoeve 2", point); }
public async void getDestination2() { RouteMap.Children.Clear(); RouteMap.Routes.Clear(); Windows.Devices.Geolocation.Geopoint point = new Windows.Devices.Geolocation.Geopoint(new Windows.Devices.Geolocation.BasicGeoposition() { Latitude = 51.58914, Longitude = 4.74304 }); MapLocationFinderResult result = await Windows.Services.Maps.MapLocationFinder.FindLocationsAsync(this.location, point); Destination = result.Locations[0]; Canvas pin = new Canvas(); Ellipse Ppin = new Ellipse() { Width = 25, Height = 25 }; Ppin.Fill = new SolidColorBrush(Windows.UI.Color.FromArgb(255, 0, 0, 0)); Ppin.Margin = new Thickness(-12.5, -12.5, 0, 0); pin.Children.Add(Ppin); try { // Windows.Devices.Geolocation.Geolocator.RequestAccessAsync().Completed() var accesStatus = await Geolocator.RequestAccessAsync(); switch(accesStatus) { case GeolocationAccessStatus.Allowed: { Geolocator geolocator = new Geolocator { DesiredAccuracy = 0 }; Geoposition pos = await geolocator.GetGeopositionAsync(); RouteMap.Children.Add(pin); Windows.UI.Xaml.Controls.Maps.MapControl.SetLocation(pin, new Geopoint(new BasicGeoposition() { Latitude = pos.Coordinate.Latitude, Longitude = pos.Coordinate.Longitude })); Windows.UI.Xaml.Controls.Maps.MapControl.SetNormalizedAnchorPoint(pin, new Point(0.5, 0.5)); currentLocation = new Geopoint(new BasicGeoposition() { Latitude = pos.Coordinate.Latitude, Longitude = pos.Coordinate.Longitude }); MapRouteFinderResult x = await MapRouteFinder.GetDrivingRouteAsync(currentLocation, Destination.Point); Windows.UI.Xaml.Controls.Maps.MapRouteView route = new Windows.UI.Xaml.Controls.Maps.MapRouteView(x.Route); RouteMap.Routes.Add(route); break; } } } catch (Exception ex) { } //Windows.Devices.Geolocation.Geolocator.RequestAccessAsync().Completed( Canvas pin2 = new Canvas(); Ellipse Ppin2 = new Ellipse() { Width = 20, Height = 20 }; Ppin2.Fill = new SolidColorBrush(Windows.UI.Color.FromArgb(255, 0, 0, 0)); Ppin2.Margin = new Thickness(-12.5, -12.5, 0, 0); pin2.Children.Add(Ppin2); RouteMap.Children.Add(pin2); Windows.UI.Xaml.Controls.Maps.MapControl.SetLocation(pin2, result.Locations[0].Point); Windows.UI.Xaml.Controls.Maps.MapControl.SetNormalizedAnchorPoint(pin2, new Point(0.5, 0.5)); RouteMap.ZoomLevel = 12; RouteMap.Center = result.Locations[0].Point; }
/// <summary> /// Initializes a new instance of the <see cref="Geopoint"/> class, a /// Wpf-enabled wrapper for <see cref="Windows.Devices.Geolocation.Geopoint"/> /// </summary> public Geopoint(Windows.Devices.Geolocation.Geopoint instance) { this.UwpInstance = instance; }
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."; }