private void map_Tapped(object sender, TappedRoutedEventArgs e) { var pos = e.GetPosition(SpeedTrapMap); Location location; //Take the tapped location and get a GPS coordinate pair from it using the Bing Maps API SpeedTrapMap.TryPixelToLocation(pos, out location); //Flyout control from Callisto. Very handy. Flyout f = new Flyout(); // Flyout is a ContentControl so set your content within it. f.Content = new NewSpeedTrap(location.Longitude, location.Latitude); f.Placement = PlacementMode.Top; f.PlacementTarget = layoutRoot; // this is an UI element (usually the sender) layoutRoot.Children.Add(f.HostPopup); f.Closed += (async(b, c) => { layoutRoot.Children.Remove(f.HostPopup); //Refresh the speed trap locations await fetchSpeedTraps(); }); f.IsOpen = true; }
/// <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 override async void OnNavigatedTo(NavigationEventArgs e) { Geolocator geolocator = new Geolocator(); if (geolocator.LocationStatus != PositionStatus.Disabled) { try { //Use the Location service to fetch the users position and move to it on the map var pos = await geolocator.GetGeopositionAsync(); var startLocation = new Location(pos.Coordinate.Latitude, pos.Coordinate.Longitude); SpeedTrapMap.SetView(startLocation); } catch { //If we don't have access to location services, default to this arbitrary location SpeedTrapMap.SetView(new Location(40.2749884116557, -97.4492259995741), 5); } } }