问题描述
在我的 UWP 应用中,我使用 Geopoint 类:
for i in lines:
if i.isupper():
## store the string
在 Winforms 应用程序中,这不可用 - 无法识别 Geopoint。是否有可用于 Winforms 应用的类似类?
同样适用于 BasicGeoposition 对象 - 无法识别。
更新
我想要 GeoPoint 和 BasicGeoposition 类,以便我可以做这样的事情:
using Windows.Devices.Geolocation;
. . .
List<Geopoint> locations;
更新 2
我尝试了答案中提供的代码:
BasicGeoposition location = new BasicGeoposition();
location.Latitude = 36.59894360222391; // Monterey == 36.6002° N
location.Longitude = -121.8616426604813; // Monterey == 121.8947° W (West is negative)
Geopoint geop = new Geopoint(location);
await map.TrySetSceneAsync(MapScene.CreateFromLocation(geop));
cmbxZoomLevels.Selectedindex = Convert.ToInt32(map.ZoomLevel - 1);
map.Style = MapStyle.Aerial3DWithRoads;
...但它不会编译。我没有 UserControl11(这是答案的代码所具有的),但我确实有一个 UserControl1,但无法识别:
这是有问题的 XAML(Bing Maps 密钥已混淆):
this.UserControl1.myMap.AnimationLevel = AnimationLevel.Full;
this.userControl11.myMap.Loaded += MyMap_Loaded;
解决方法
对于那些希望使用与 Windows Community Toolkit Map Control 不同的 Bing Maps WPF Control 的人,您可以按照以下步骤使用 Windows Community Toolkit Map Control for Windows Forms。 >
注意:Windows 10(引入 v10.0.17709.0)是先决条件。
-
创建一个 Windows 窗体应用程序(.NET Framework >=4.6.2 - 我自己尝试过 4.7.2)
-
安装 Microsoft.Toolkit.Forms.UI.Controls NuGet 包。
-
添加 app.manifest 文件:右键单击项目 → 添加新项 → 选择 应用程序清单文件(仅限 Windows) em> 位于 General 节点下。
-
打开 app.manifest 文件并取消注释
supportedOS
下的<!-- Windows 10 -->
:<!-- Windows 10 --> <supportedOS Id="{8e0f7a12-bfb3-4fe8-b9a5-48fd50a15a9a}" />
-
处理表单的
Load
事件并添加以下代码:private void Form1_Load(object sender,EventArgs e) { var map = new MapControl(); map.Dock = DockStyle.Fill; map.MapServiceToken = "YOUR KEY"; map.LoadingStatusChanged += async (obj,args) => { if (map.LoadingStatus == MapLoadingStatus.Loaded) { var cityPosition = new BasicGeoposition() { Latitude = 47.604,Longitude = -122.329 }; var cityCenter = new Geopoint(cityPosition); await map.TrySetViewAsync(cityCenter,12); } }; this.Controls.Add(map); }
还要确保包含必需的用途:
using Microsoft.Toolkit.Forms.UI.Controls; using Microsoft.Toolkit.Win32.UI.Controls.Interop.WinRT;
注意 1: 我无法在设计器中添加控件,因为当我尝试在表单上删除控件时,设计时出现异常,因此我决定在运行时使用添加它-时间。
注意 2: 您需要 Get a Key 才能使用地图;但是出于测试目的,您可能会忽略获取密钥。
-
运行您的应用程序并查看结果:
更多信息
- MapControl for Windows Forms and WPF
- Source code:
Microsoft.Toolkit.Forms.UI.Controls.MapControl
- WinForms 控件是 WPF
Windows.UI.Xaml.Controls.Maps.MapControl
的包装器 - Display maps with 2D,3D,and Streetside views
要设置 Bing Maps WPF control 的视图,可以使用 SetView
方法。该方法有不同的重载,例如,您可以将 Location
(您根据所需位置的纬度和经度创建)和缩放级别传递给该方法,如下所示:
var location = new Location(47.604,-122.329);
this.userControl11.myMap.SetView(location,12);
同样可以通过设置 Center
和 ZoomLevel
来实现。
下载或克隆示例
您可以从这里下载或关闭工作示例:
分步示例 - 放大西雅图作为初始视图
-
按照 this post 中的说明创建使用 WPF Bing 地图控件的 Windows 窗体项目。
-
处理
Form
的 Load 事件并使用以下代码:private void Form1_Load(object sender,EventArgs e) { this.userControl11.myMap.AnimationLevel = AnimationLevel.Full; this.userControl11.myMap.Loaded += MyMap_Loaded; } private void MyMap_Loaded(object sender,System.Windows.RoutedEventArgs e) { var location = new Location(47.604,-122.329); this.userControl11.myMap.SetView(location,12); }
确保使用
using Microsoft.Maps.MapControl.WPF;
。
更多信息:
您可能需要查看以下链接以获取更多信息: