加载 UWP 应用程序时未显示地图
Map not showing up on the loading of UWP Application
加载西雅图地图的是我的 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();
}
}
}
- 我尝试插入我的 MapServiceToken,但我仍然看不到它。
纬度7,经度-122在太平洋中部,不是西雅图。也许你的意思是 47,-122?
加载西雅图地图的是我的 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();
}
}
}
- 我尝试插入我的 MapServiceToken,但我仍然看不到它。
纬度7,经度-122在太平洋中部,不是西雅图。也许你的意思是 47,-122?