在WPF GMAP中没有显示地图.从c# Visual Studio 2013中学习.NET

本文关键字:Visual Studio 2013 学习 NET 地图 GMAP WPF 显示 | 更新日期: 2023-09-27 18:16:11

我想在基于OpenStreetMap的地图上显示一个点。我在GMAP工作。WPF来自c# Visual Studio 2013.

当我运行它时,只显示了一个窗口。但是,地图不能显示。

如何解决这个问题?

下面是我的代码:
MainWindow.xaml.cs:
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using GMap.NET;
using GMap.NET.WindowsPresentation;
using GMap.NET.MapProviders;
namespace try_gmap_wpf
{
  /// <summary>
 /// Interaction logic for MainWindow.xaml
 /// </summary>
 public partial class MainWindow : Window
 {
    public MainWindow()
    {
        InitializeComponent();
        GMapControl gMapControl1 = new GMapControl();
        myMap.MapProvider = OpenStreetMapProvider.Instance;
        //myMap.SetPositionByKeywords("Canada");
        //Get tiles from server only
        myMap.Manager.Mode = AccessMode.ServerOnly;
        //Not use proxy
        //Center map on a point
        myMap.Position = new PointLatLng(42.742826, -77.030212);
        //Zoom min/max; default both = 2
        myMap.MinZoom = 1;
        myMap.MaxZoom = 2;
        //Set zoom
        myMap.Zoom = 0;
        myMap.ShowCenter = true;
    }
  }
}
MainWindow.xaml designer:
<Window
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:WindowsPresentation="clr-namespace:GMap.NET.WindowsPresentation;assembly=GMap.NET.WindowsPresentation" x:Class="try_gmap_wpf.MainWindow"
    xmlns:m="clr-namespace:GMap.NET.WindowsPresentation;assembly=GMap.NET.WindowsPresentation"
    Title="MainWindow" Height="500" Width="900">
<Grid>
    <WindowsPresentation:GMapControl Name="myMap" HorizontalAlignment="Left" Height="500" Margin="10,10,0,0" VerticalAlignment="Top" Width="900"/>
 </Grid>
</Window>

在WPF GMAP中没有显示地图.从c# Visual Studio 2013中学习.NET

尝试更改缩放设置:

...
myMap.MinZoom = 3;
myMap.MaxZoom = 17;
...