加载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?

最新更新