C# - Cannot display MapControl using Bing Map

243 views Asked by At

I have a control folder like below: XAML:

<Maps:MapControl x:Name="MapControl" Grid.Row="5" Grid.ColumnSpan="2" Margin="20,10,15,15" Visibility="Visible"
                                     Height="200" HorizontalAlignment="Left" VerticalAlignment="Top" BorderBrush="Black" BorderThickness="1"/>

Code:

MapControl.MapServiceToken = "MyMapToken";
                        ListingClass listing = new ListingClass();
                        listing.Latitude = Double.Parse("-7.78183620", CultureInfo.InvariantCulture);
                        listing.Longitude = Double.Parse("110.40856360", CultureInfo.InvariantCulture);

                        // Specify a known location.
                        BasicGeoposition snPosition = new BasicGeoposition() { Latitude = listing.Latitude, Longitude = listing.Longitude };
                        Geopoint snPoint = new Geopoint(snPosition);

                        // Create a MapIcon.
                        MapIcon mapIcon1 = new MapIcon();
                        mapIcon1.Image =
                            RandomAccessStreamReference.CreateFromUri(new Uri("ms-appx:///images/map-pin-red-md1.png"));
                        mapIcon1.Location = snPoint;
                        mapIcon1.NormalizedAnchorPoint = new Point(0.5, 1.0);
                        mapIcon1.Title = pageTitle.Text;
                        mapIcon1.ZIndex = 0;

                        // Add the MapIcon to the map.
                        MapControl.MapElements.Add(mapIcon1);

                        // Center the map over the POI.
                        MapControl.Center = snPoint;
                        MapControl.ZoomLevel = 14;
                        MapControl.LandmarksVisible = true;

I'm having trouble, ie can not display folder (only white pages only). How to handle it?

I want to ask for a free bing developer license, is there a limit on the number of applications that can use big map? Because in the previous application bing map can be displayed (I use a different key according to the name of the application).

1

There are 1 answers

0
Sunteen Wu On BEST ANSWER

I'm having trouble, ie can not display folder (only white pages only). How to handle it?

It seems like the MapControl doesn't have default Width and Height, the recommend way is not to set any properties (for example, Height,Margin and so on) to let it fit the parent container. And the map will be shown. For example, your map located in one row of Grid, you can just define the map like follows:

<Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
  <Grid.RowDefinitions>
    <RowDefinition Height="*"/>
    <RowDefinition Height="*"/>
    <RowDefinition Height="*"/>
  </Grid.RowDefinitions>
  <Grid.ColumnDefinitions>
      <ColumnDefinition Width="*"/>
      <ColumnDefinition Width="*"/>
      <ColumnDefinition Width="*"/>
  </Grid.ColumnDefinitions> 
    <maps:MapControl x:Name="MapControl" Grid.Row="1" Grid.ColumnSpan="2" BorderBrush="Black" BorderThickness="1"/>
</Grid>

The reason for not recommend is because without setting the Height and Width the map can adaptive different UWP devices kindly. If you do want to set the height property, to make the map shown,you may need to set the width property or HorizontalAlignment="Stretch" to indicate the width as well. For example:

<maps:MapControl x:Name="MapControl" Height="200" HorizontalAlignment="Stretch"  BorderBrush="Black" BorderThickness="1" Grid.Row="1" Grid.ColumnSpan="2"/>
<maps:MapControl x:Name="MapControl" Height="200" Width="200"  BorderBrush="Black" BorderThickness="1"Grid.Row="1" Grid.ColumnSpan="2" />

I want to ask for a free bing developer license, is there a limit on the number of applications that can use big map?

Bing Map should not have limited on number of applications if you're using different keys for every application. But you may met billable APIs when you using these keys.