1

我想在基于OpenStreetMap的地图上显示一个点。我正在使用C# Visual Studio 2013的 GMAP.NET( http://greatmaps.codeplex.com/上的一个控件库)WPF 。

当我运行它时,只出现了一个窗口。但是,地图无法显示。

我该如何解决这个问题?

这是我的代码:

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>
4

1 回答 1

1

尝试更改缩放设置:

...
myMap.MinZoom = 3;
myMap.MaxZoom = 17;
...
于 2015-10-05T21:35:08.653 回答