简体   繁体   中英

Map not showing up on the loading of UWP Application

It is my UWP Application to load the map of Seattle. My problem is that as I load my UWP application, instead of showing me the map it shows me the blank background with dark color. I am trying to solve this problem from last few hours but can't figure out where I am wrong.

XAML

<Page
    x:Class="MyMapApp.MapPage"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:local="using:MyMapApp"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    xmlns:maps="using:Windows.UI.Xaml.Controls.Maps"
    mc:Ignorable="d">
    <Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
        <StackPanel>
            <StackPanel x:Name="SearchControls"
                        Orientation="Horizontal">
                <CheckBox x:Name="TrafficCheckBox"
                          Content="Show Traffic"
                          Width="100"
                          Height="50"
                          Margin="15,35,15,15"
                          Checked="TrafficCheckBox_Checked"
                          Unchecked="TrafficCheckBox_Unchecked"/>
                <Button x:Name="MapStyleButton"
                        Content="Aerial"
                        Width="100"
                        Height="50"
                        Margin="15"
                        Click="MapStyleButton_Click" />
            </StackPanel>
            <maps:MapControl x:Name="MapControl"
                             Height="500"
                             ZoomInteractionMode="GestureAndControl"
                             TiltInteractionMode="GestureAndControl" 
                             CacheMode="BitmapCache" 
                             CanDrag="True"
                             MapServiceToken="<<MY KEY>>"/>  
        </StackPanel>
    

    </Grid>
</Page>

CS

using System;
using Windows.Devices.Geolocation;
using Windows.UI.Popups;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Controls.Maps;
using System.Reflection;

namespace MyMapApp
{
    /// <summary>
    /// An empty page that can be used on its own or navigated to within a Frame.
    /// </summary>
    public sealed partial class MapPage : Page
    {
        public MapPage()
        {
            this.InitializeComponent();
            MapControl.Loaded += MapControl_Loaded;
            MapControl.MapTapped += MapControl_MapTapped;
        }

        private void MapControl_Loaded(object sender, RoutedEventArgs e)
        {
            MapControl.Center = new Geopoint(new BasicGeoposition()
            {
                //Geopoint for Seattle
                Latitude = 7.604,
                Longitude = -122.329
            });
            //MapControl.StyleSheet = MapStyleSheet.RoadDark();
            MapControl.Style = MapStyle.Aerial3DWithRoads;
            MapControl.ZoomLevel = 12;
            MapControl.LandmarksVisible = true;
        }

        private void TrafficCheckBox_Checked(object sender, RoutedEventArgs e)
        {
            MapControl.TrafficFlowVisible = true;
        }

        private void TrafficCheckBox_Unchecked(object sender, RoutedEventArgs e)
        {
            MapControl.TrafficFlowVisible = false;
        }

        private void MapStyleButton_Click(object sender, RoutedEventArgs e)
        {
            if(MapControl.Style == Windows.UI.Xaml.Controls.Maps.MapStyle.Aerial)
            {
                MapControl.Style = Windows.UI.Xaml.Controls.Maps.MapStyle.Road;
                MapStyleButton.Content = "Aerial";
            }
            else
            {
                MapControl.Style = Windows.UI.Xaml.Controls.Maps.MapStyle.Aerial;
                MapStyleButton.Content = "Road";
            }
        }

        private async void MapControl_MapTapped(Windows.UI.Xaml.Controls.Maps.MapControl sender, Windows.UI.Xaml.Controls.Maps.MapInputEventArgs args)
        {
            var tappedGeoPosition = args.Location.Position;
            string status =
                $"Map tapped at \nLatitude: {tappedGeoPosition.Latitude}" +
                $"\nLongitude: {tappedGeoPosition.Longitude}";

            var messageDialog = new MessageDialog(status);
            await messageDialog.ShowAsync();
        }
    }

}
  1. I tried to inserting my MapServiceToken still I am not able to see it.

Latitude 7, longitude -122 is in the middle of the Pacific ocean, not Seattle. Perhaps you meant 47, -122?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM