void MyMap_PointerPressedOverride(object sender, PointerRoutedEventArgs e) { Bing.Maps.Location l = new Bing.Maps.Location(); this.ControlMap.TryPixelToLocation(e.GetCurrentPoint(this.ControlMap).Position, out l); Bing.Maps.Pushpin pushpin = new Bing.Maps.Pushpin(); pushpin.SetValue(Bing.Maps.MapLayer.PositionProperty, l); this.ControlMap.Children.Add(pushpin); }
private void ItemsListView_Tapped(object sender, Windows.UI.Xaml.Input.TappedRoutedEventArgs e) { SelectionsMapLayer.Children.Clear(); if (ItemsListView.SelectedItems.Count > 0) { if ((ListViewMode.MyGeofences == _currentListViewMode) || (ListViewMode.Places == _currentListViewMode)) { Bing.Maps.Location itemLocation = null; // Add pushpins for all selected items foreach (var item in ItemsListView.SelectedItems) { if (ListViewMode.MyGeofences == _currentListViewMode) { GeofenceItem g = item as GeofenceItem; Geocircle geocircle = g.Geofence.Geoshape as Geocircle; itemLocation = new Bing.Maps.Location(geocircle.Center.Latitude, geocircle.Center.Longitude); } else { Venue v = item as Venue; itemLocation = new Bing.Maps.Location(v.Latitude, v.Longitude); } var pushPin = new Bing.Maps.Pushpin() { Background = new Windows.UI.Xaml.Media.SolidColorBrush(Windows.UI.Color.FromArgb(100, 255, 23, 23)), }; SelectionsMapLayer.Children.Add(pushPin); Bing.Maps.MapLayer.SetPosition(pushPin, itemLocation); } // Center the map on the last seleced item Map.SetView(itemLocation); } } }
void VendFinderApp_PointerPressedOverride(object sender, PointerRoutedEventArgs e) { Bing.Maps.Location loc = new Bing.Maps.Location(); this.VendFinderApp.TryPixelToLocation(e.GetCurrentPoint(this.VendFinderApp).Position, out loc); Bing.Maps.Pushpin pushPin = new Bing.Maps.Pushpin(); pushPin.SetValue(Bing.Maps.MapLayer.PositionProperty, loc); this.VendFinderApp.Children.Add(pushPin); // Add code to prompt user to enter VendMachine metadata... inputPrompt = new TextBox(); inputPrompt.Height = (1 / 4) * Height; inputPrompt.Width = Width; inputPrompt.SetValue(Bing.Maps.MapLayer.PositionProperty, loc); inputPrompt.PlaceholderText = "Enter location of Vending Machine..."; inputPrompt.IsEnabled = true; inputPrompt.UpdateLayout(); inputPrompt.Opacity = 1; inputPrompt.Visibility = Visibility.Visible; VendFinderApp.Children.Add(inputPrompt); // Generic file name for file which stores user-prescribed location info. //string name = "database.txt"; // Package the info file and save it to the user's system. //StorageFile storeFile = // await storageFolder.CreateFileAsync(name, CreationCollisionOption.GenerateUniqueName); mLoc = loc.Latitude.ToString() + "|" + loc.Longitude.ToString(); //storeFile = await storageFolder.GetFileAsync("dataBase.txt"); //await FileIO.WriteTextAsync(storeFile, loc.Latitude.ToString() + " " + loc.Longitude.ToString()); pinBeingPlaced = true; }
// Note: these should not catch exceptions, let them propagate up to the UI handlers /// <summary> /// Retrieves the list of venues based on the current location. /// </summary> private async Task GetNearbyVenuesAsync() { _currentListViewMode = ListViewMode.Places; var position = _geoposition.Coordinate.Point.Position; bool accessDenied = false; // If selected index is valid (i.e. the user clicked on an exiting item), don't re-query and just use the cache. if ((_venuesCache != null) && (_currentSelectedIndex == -1)) { // Re-query if we moved far enough if (GetDistanceInMetersBetweenPositions(position, _venuesCachePosition) >= Constants.VenuesQueryDistanceThresholdMeters) { _venuesCache = null; } } if (_venuesCache == null) { Title.Text = "Finding Places from Foursquare ..."; var resourceUri = String.Format("https://api.foursquare.com/v2/venues/explore?ll={0},{1}&limit={2}&v={3}", Uri.EscapeDataString(position.Latitude.ToString()), Uri.EscapeDataString(position.Longitude.ToString()), Settings.QueryLimit, Constants.ApiVerifiedDate); try { HttpResponseMessage response = await _httpClient.GetAsync(new Uri(resourceUri)); switch (response.StatusCode) { case HttpStatusCode.Ok: var responseBodyAsText = await response.Content.ReadAsStringAsync(); var responseBodyAsJson = JsonObject.Parse(responseBodyAsText); _venuesCache = Venue.ListFromJson(responseBodyAsJson["response"].GetObject()) as List <Venue>; _venuesCachePosition = position; break; case HttpStatusCode.Unauthorized: // token was revoked Logger.Trace(TraceLevel.Error, "User disconnected this app from the Foursquare Settings page: " + response.StatusCode.ToString()); accessDenied = true; break; default: Logger.Trace(TraceLevel.Error, "Failed to query venues from Foursquare: " + response.StatusCode.ToString()); break; } } catch (UnauthorizedAccessException) { accessDenied = true; } } if (accessDenied) { Logger.Trace(TraceLevel.Info, "Access denied, deleting state."); await DeleteStateAsync(); } if (_venuesCache != null) { Title.Text = _venuesCache.Count + " Recommended Places"; ItemsListView.ItemsSource = _venuesCache; ScrollListViewToCurrentSelection(); // Update map int index = 0; VenuesMapLayer.Children.Clear(); foreach (var v in _venuesCache) { var pushpin = new Bing.Maps.Pushpin(); pushpin.Text = index.ToString(); pushpin.Tapped += VenuePushpin_Tapped; Bing.Maps.MapLayer.SetPosition(pushpin, new Bing.Maps.Location(v.Latitude, v.Longitude)); VenuesMapLayer.Children.Add(pushpin); index++; } } else { Title.Text = "Places Unavailable"; } }
/// <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. The Parameter /// property is typically used to configure the page.</param> protected async override void OnNavigatedTo(NavigationEventArgs e) { IHttpFilter filter = new AuthFilter(new HttpBaseProtocolFilter()); _httpClient = new HttpClient(filter); _isConnectedToInternet = (null != NetworkInformation.GetInternetConnectionProfile()); NetworkInformation.NetworkStatusChanged += OnNetworkStatusChanged; Logger.Initialize(LoggerTextBox, LoggerScrollViewer); await LogBackgroundEventsAsync(); ShowStatus("Waiting for location..."); try { _geolocator = new Geolocator(); _geoposition = await _geolocator.GetGeopositionAsync(); ClearStatus(); var position = _geoposition.Coordinate.Point.Position; Logger.Trace(TraceLevel.Info, String.Format("Current Location: {0}, Accuracy: {1} meters", Logger.FormatLatLong(position.Latitude, position.Longitude), _geoposition.Coordinate.Accuracy)); // Initialize map var mapCenter = new Bing.Maps.Location(position.Latitude, position.Longitude); Map.SetView(mapCenter, Constants.DefaultMapZoomLevel); _currentLocationPushpin = new Bing.Maps.Pushpin(); CurrentPositionMapLayer.Children.Add(_currentLocationPushpin); Bing.Maps.MapLayer.SetPosition(_currentLocationPushpin, mapCenter); // Register for position changed events _geolocator.PositionChanged += OnGeopositionChanged; // Loop through all background tasks to see if our background task is already registered foreach (var cur in BackgroundTaskRegistration.AllTasks) { if (cur.Value.Name == _backgroundTaskName) { _geofenceTask = cur.Value; break; } } if (_geofenceTask != null) { // Associate an event handler with the existing background task _geofenceTask.Completed += new BackgroundTaskCompletedEventHandler(OnCompleted); } else { // Get permission for a background task from the user. If the user has already answered once, // this does nothing and the user must manually update their preference via PC Settings. var backgroundAccessStatus = await BackgroundExecutionManager.RequestAccessAsync(); switch (backgroundAccessStatus) { case BackgroundAccessStatus.Unspecified: case BackgroundAccessStatus.Denied: ShowStatus("This application must be added to the lock screen in order to do automatic checkins."); break; default: break; } // Register the background task. var geofenceTaskBuilder = new BackgroundTaskBuilder(); geofenceTaskBuilder.Name = _backgroundTaskName; geofenceTaskBuilder.TaskEntryPoint = _backgroundTaskEntryPoint; // Create a new location trigger var trigger = new LocationTrigger(LocationTriggerType.Geofence); // Associate the location trigger with the background task builder geofenceTaskBuilder.SetTrigger(trigger); // Ensure there is an internet connection before the background task is launched. var condition = new SystemCondition(SystemConditionType.InternetAvailable); geofenceTaskBuilder.AddCondition(condition); // Register the background task _geofenceTask = geofenceTaskBuilder.Register(); // Associate an event handler with the new background task _geofenceTask.Completed += new BackgroundTaskCompletedEventHandler(OnCompleted); Logger.Trace(TraceLevel.Debug, "Background registration succeeded"); } } catch (System.UnauthorizedAccessException) { ShowStatus("Location access denied, please go to Settings -> Permissions to grant this app access to your location."); Logger.Trace(TraceLevel.Warn, "Access denied when getting location"); } catch (TaskCanceledException) { ShowStatus("Location acquisition was canceled. Close and re-launch this app if you would like to try again."); Logger.Trace(TraceLevel.Warn, "Canceled getting location"); } catch (Exception ex) { Logger.Trace(TraceLevel.Error, "Could not acquire location or register background trigger: " + Logger.FormatException(ex)); } Settings.Changed += OnSettingsChanged; Logger.Trace(TraceLevel.Info, "Foursquare query limit setting: " + Settings.QueryLimit + " places"); Logger.Trace(TraceLevel.Info, "Geofence creation radius setting: " + Settings.GeofenceRadiusMeters + " meters"); }
public void AddMapPushPin(DataItem item) { var pushpinBorn = new Bing.Maps.Pushpin(); pushpinBorn.Text = "1"; pushpinBorn.Background = new SolidColorBrush(Windows.UI.Colors.Blue); Bing.Maps.MapLayer.SetPosition(pushpinBorn, new Bing.Maps.Location(item.PlaceOfBirthLat, item.PlaceOfBirthLong)); myMap.Children.Add(pushpinBorn); var pushpinDeath = new Bing.Maps.Pushpin(); pushpinDeath.Text = "2"; pushpinDeath.Background = new SolidColorBrush(Windows.UI.Colors.Red); Bing.Maps.MapLayer.SetPosition(pushpinDeath, new Bing.Maps.Location(item.PlaceOfDeathLat, item.PlaceOfDeathLong)); myMap.Children.Add(pushpinDeath); }
// This is the task which runs to load database information to the app. public void loadData() { List <string> machineNames = new List <string>(); List <double> machineCoordLat = new List <double>(); List <double> machineCoordLong = new List <double>(); using (var queryContext = new VendingInfoContext()) { try { // Finish implementing database query system! var machineEntities = queryContext.Machines.ToList(); // Organizes pin data from SQLite database into compartmentalized variables // for use within the application. for (int i = 0; i < machineEntities.Count(); i++) { machineNames.Add(machineEntities.ElementAt(i).machineName); double tempLat = double.Parse(machineEntities.ElementAt(i).machineLocation.Substring(0, 16)); double tempLong = double.Parse(machineEntities.ElementAt(i).machineLocation.Substring(17)); machineCoordLat.Add(tempLat); machineCoordLong.Add(tempLong); } // Not sure if this actually helps with anything... Debug.WriteLine(machineEntities[0].Id); } catch (Exception e) { // Thrown if an exception occurs. Debug.WriteLine("No elements in database at this time...: " + e); } } // Places all stored location pins onto the application's map. for (int i = 0; i < machineNames.Count(); i++) { Bing.Maps.Location loc = new Bing.Maps.Location(machineCoordLat.ElementAt(i), machineCoordLong.ElementAt(i)); Bing.Maps.Pushpin pushPin = new Bing.Maps.Pushpin(); pushPin.SetValue(Bing.Maps.MapLayer.PositionProperty, loc); this.VendFinderApp.Children.Add(pushPin); // Add textbox containing location name to placed pin location... TextBox locText = new TextBox(); locText.Height = (1 / 4) * Height; locText.Width = Width; locText.SetValue(Bing.Maps.MapLayer.PositionProperty, loc); locText.Text = machineNames.ElementAt(i); locText.IsEnabled = true; locText.UpdateLayout(); locText.Opacity = 1; locText.Visibility = Visibility.Visible; locText.IsReadOnly = true; VendFinderApp.Children.Add(locText); } //double lat = double.Parse(universalText.Substring(0, 16)); //double longi = double.Parse(universalText.Substring(17)); //Bing.Maps.Location loc = new Bing.Maps.Location(lat, longi); //Bing.Maps.Pushpin pushPin = new Bing.Maps.Pushpin(); //pushPin.SetValue(Bing.Maps.MapLayer.PositionProperty, loc); //this.VendFinderApp.Children.Add(pushPin); }