none
Looking for Bing Venue Maps XAML example RRS feed

  • Question

  • I am using Bing Maps in my WinRT store app and would like to add Venue Maps. How do I do that in C#, XAML?

    Thanks

    John

    Friday, October 26, 2012 12:24 PM

Answers

  • You have to use C# for Venue Maps.

    Here are code blocks from couple samples that haven't been uploaded yet.

    Sample on opening the venue directory when a user clicks on a venue.

        <Grid>
            <bm:Map x:Name="map" Credentials="INSERT_YOUR_BING_MAPS_KEY"/>
            <Grid x:Name="buttonGrid" VerticalAlignment="Top" HorizontalAlignment="Left" Margin="10,80,10,10"  Height="90" Width="200" Background="Gray">
                <StackPanel x:Name="venueMapControlPanel" Orientation="Vertical">
                    <Button Content="Clear Venue" Click="ClearVenueButton_Click" Margin="0,2.5" Width="180" HorizontalAlignment="Center"/>
                    <Button Content="Show/Hide Directory" Click="ShowHideDirectoryButton_Click" Margin="0,2.5" Width="180" HorizontalAlignment="Center"/>
                </StackPanel>
            </Grid>
            <Grid x:Name="directoryGrid" Visibility="Collapsed" HorizontalAlignment="Right" Margin="10,80,10,75"  Width="300" Background="Gray">
                <Grid Margin="10" Background="#FF535353" x:Name="directoryPanelParent">
                </Grid>
            </Grid>
        </Grid>
        public sealed partial class MainPage : Page
        {
            public MainPage()
            {
                this.InitializeComponent();
                {
                    map.Center = new Location(47.615739, -122.20403);
                    map.ZoomLevel = 16;
                    if (map.VenueManager != null)
                    {
                        map.VenueManager.ShowFloorControl = true;
                        map.VenueManager.ActiveVenueChanged += VenueManager_ActiveVenueChanged;
                    }
                }
            }
    
            protected override void OnNavigatedTo(NavigationEventArgs e)
            {
            }
    
            void VenueManager_ActiveVenueChanged(object sender, Bing.Maps.VenueMaps.ActiveVenueChangedEventArgs e)
            {
                if (map != null && map.VenueManager != null)
                {
                    ShowHideDirectory(map.VenueManager.ActiveVenue == null ? false : true);
                }
            }
    
            void DirectoryPanel_CloseTapped(object sender, TappedRoutedEventArgs e)
            {
                ShowHideDirectory(false);
            }
    
            private void ShowHideDirectoryButton_Click(object sender, RoutedEventArgs e)
            {
                if (directoryGrid != null)
                {
                    bool showing = directoryGrid.Visibility == Windows.UI.Xaml.Visibility.Visible;
                    ShowHideDirectory(!showing);
                }
            }
    
            private void ClearVenueButton_Click(object sender, RoutedEventArgs e)
            {
                if (map != null && map.VenueManager != null && map.VenueManager.ActiveVenue != null)
                {
                    map.VenueManager.ClearActiveVenue();
                }
            }
    
            void ShowHideDirectory(bool show)
            {
                if (show)
                {
                    if (map != null && map.VenueManager != null &&
                        map.VenueManager.GetDirectoryPanel() != null && directoryPanelParent != null)
                    {
                        if (directoryPanelParent.Children.IndexOf(map.VenueManager.GetDirectoryPanel()) == -1)
                        {
                            directoryPanelParent.Children.Add(map.VenueManager.GetDirectoryPanel());
                            map.VenueManager.GetDirectoryPanel().CloseTapped += DirectoryPanel_CloseTapped;
                        }
                    }
                }
    
                if (directoryGrid != null)
                {
                    directoryGrid.Visibility = show ? Windows.UI.Xaml.Visibility.Visible : Windows.UI.Xaml.Visibility.Collapsed;
                }
            }
        }

    Here is another example.  This one searches for all the venues within 10000 square meter, and open the closest one.

                if (map != null && map.VenueManager != null)
                {
                    // find all the venues in 10000 square meters
                    NearbyVenueOptions options = new NearbyVenueOptions(map.Center, 10000);
                    NearbyVenueCollection nearbyVenues = null;
                    try
                    {
                        nearbyVenues = await map.VenueManager.GetNearbyVenuesAsync(options);
                    }
                    catch (Exception)
                    {
                        // exception is thrown when GetNearbyVenuesAsync finds nothing.
                        // it's not supposed to, but catch the exception as work around for now.
                    }
    
                    if (nearbyVenues != null && nearbyVenues.Count > 0)
                    {
                        // nearby venue is sorted from closest to furthest, index 0 is the closest.
                        if (map != null && map.VenueManager != null && nearbyVenues[0].Metadata != null)
                        {
                            // query for the cloest nearby venue, and set it as ActiveVenue
                            map.VenueManager.ActiveVenue = await map.VenueManager.CreateVenueMapAsync(nearbyVenues[0].Metadata.VenueId);
                            if (map.VenueManager.ActiveVenue != null)
                            {
                                // Pan/zoom the map to the best map view for this venue.
                                map.SetView(map.VenueManager.ActiveVenue.Bounds);
                            }
                        }
                    }
                }

    I hope this would help get you started.

    Friday, October 26, 2012 5:27 PM

All replies

  • You have to use C# for Venue Maps.

    Here are code blocks from couple samples that haven't been uploaded yet.

    Sample on opening the venue directory when a user clicks on a venue.

        <Grid>
            <bm:Map x:Name="map" Credentials="INSERT_YOUR_BING_MAPS_KEY"/>
            <Grid x:Name="buttonGrid" VerticalAlignment="Top" HorizontalAlignment="Left" Margin="10,80,10,10"  Height="90" Width="200" Background="Gray">
                <StackPanel x:Name="venueMapControlPanel" Orientation="Vertical">
                    <Button Content="Clear Venue" Click="ClearVenueButton_Click" Margin="0,2.5" Width="180" HorizontalAlignment="Center"/>
                    <Button Content="Show/Hide Directory" Click="ShowHideDirectoryButton_Click" Margin="0,2.5" Width="180" HorizontalAlignment="Center"/>
                </StackPanel>
            </Grid>
            <Grid x:Name="directoryGrid" Visibility="Collapsed" HorizontalAlignment="Right" Margin="10,80,10,75"  Width="300" Background="Gray">
                <Grid Margin="10" Background="#FF535353" x:Name="directoryPanelParent">
                </Grid>
            </Grid>
        </Grid>
        public sealed partial class MainPage : Page
        {
            public MainPage()
            {
                this.InitializeComponent();
                {
                    map.Center = new Location(47.615739, -122.20403);
                    map.ZoomLevel = 16;
                    if (map.VenueManager != null)
                    {
                        map.VenueManager.ShowFloorControl = true;
                        map.VenueManager.ActiveVenueChanged += VenueManager_ActiveVenueChanged;
                    }
                }
            }
    
            protected override void OnNavigatedTo(NavigationEventArgs e)
            {
            }
    
            void VenueManager_ActiveVenueChanged(object sender, Bing.Maps.VenueMaps.ActiveVenueChangedEventArgs e)
            {
                if (map != null && map.VenueManager != null)
                {
                    ShowHideDirectory(map.VenueManager.ActiveVenue == null ? false : true);
                }
            }
    
            void DirectoryPanel_CloseTapped(object sender, TappedRoutedEventArgs e)
            {
                ShowHideDirectory(false);
            }
    
            private void ShowHideDirectoryButton_Click(object sender, RoutedEventArgs e)
            {
                if (directoryGrid != null)
                {
                    bool showing = directoryGrid.Visibility == Windows.UI.Xaml.Visibility.Visible;
                    ShowHideDirectory(!showing);
                }
            }
    
            private void ClearVenueButton_Click(object sender, RoutedEventArgs e)
            {
                if (map != null && map.VenueManager != null && map.VenueManager.ActiveVenue != null)
                {
                    map.VenueManager.ClearActiveVenue();
                }
            }
    
            void ShowHideDirectory(bool show)
            {
                if (show)
                {
                    if (map != null && map.VenueManager != null &&
                        map.VenueManager.GetDirectoryPanel() != null && directoryPanelParent != null)
                    {
                        if (directoryPanelParent.Children.IndexOf(map.VenueManager.GetDirectoryPanel()) == -1)
                        {
                            directoryPanelParent.Children.Add(map.VenueManager.GetDirectoryPanel());
                            map.VenueManager.GetDirectoryPanel().CloseTapped += DirectoryPanel_CloseTapped;
                        }
                    }
                }
    
                if (directoryGrid != null)
                {
                    directoryGrid.Visibility = show ? Windows.UI.Xaml.Visibility.Visible : Windows.UI.Xaml.Visibility.Collapsed;
                }
            }
        }

    Here is another example.  This one searches for all the venues within 10000 square meter, and open the closest one.

                if (map != null && map.VenueManager != null)
                {
                    // find all the venues in 10000 square meters
                    NearbyVenueOptions options = new NearbyVenueOptions(map.Center, 10000);
                    NearbyVenueCollection nearbyVenues = null;
                    try
                    {
                        nearbyVenues = await map.VenueManager.GetNearbyVenuesAsync(options);
                    }
                    catch (Exception)
                    {
                        // exception is thrown when GetNearbyVenuesAsync finds nothing.
                        // it's not supposed to, but catch the exception as work around for now.
                    }
    
                    if (nearbyVenues != null && nearbyVenues.Count > 0)
                    {
                        // nearby venue is sorted from closest to furthest, index 0 is the closest.
                        if (map != null && map.VenueManager != null && nearbyVenues[0].Metadata != null)
                        {
                            // query for the cloest nearby venue, and set it as ActiveVenue
                            map.VenueManager.ActiveVenue = await map.VenueManager.CreateVenueMapAsync(nearbyVenues[0].Metadata.VenueId);
                            if (map.VenueManager.ActiveVenue != null)
                            {
                                // Pan/zoom the map to the best map view for this venue.
                                map.SetView(map.VenueManager.ActiveVenue.Bounds);
                            }
                        }
                    }
                }

    I hope this would help get you started.

    Friday, October 26, 2012 5:27 PM
  • Awesome, thank you so much!
    Monday, November 5, 2012 5:09 PM