繁体   English   中英

Map 未显示在 UWP 应用程序的加载中

[英]Map not showing up on the loading of UWP Application

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

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?

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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