未在加载UWP应用程序时显示地图

问题描述

这是我的UWP应用程序,用于加载西雅图地图。我的问题是,当我加载UWP应用程序时,没有向我显示地图,而是向我显示了深色的空白背景。我试图从最近几个小时解决此问题,但无法弄清楚我哪里错了。

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. 我仍然尝试插入我的MapServiceToken,但我仍然看不到它。

解决方法

纬度7,经度-122位于太平洋中部,而不是西雅图。也许您的意思是47,-122?

相关问答

错误1:Request method ‘DELETE‘ not supported 错误还原:...
错误1:启动docker镜像时报错:Error response from daemon:...
错误1:private field ‘xxx‘ is never assigned 按Alt...
报错如下,通过源不能下载,最后警告pip需升级版本 Requirem...