C# 在 Windows 窗体应用程序中显示地图

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/424770/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-04 02:52:39  来源:igfitidea点击:

Display a map in a Windows Form app

c#winformsmaps

提问by Sailing Judo

I built a Winform app several months ago that schedules appointments for repair techs. I'd like to update the app by adding a map for the customer's address on the customer form, and then print that map on the report the techs take when they leave the office.

几个月前,我构建了一个 Winform 应用程序,用于安排维修技术人员的约会。我想通过在客户表单上添加客户地址的地图来更新应用程序,然后将该地图打印在技术人员离开办公室时所采取的报告上。

I've been looking around but I haven't found a good solution for this yet.

我一直在环顾四周,但我还没有找到一个好的解决方案。

I currently have an address for the customer. What I'd like to do is submit the address to one of the popular online map sites and get a minimap of the locale. I can almostdo this with Google maps using their embedded link feature. I can get the following HTML after adding an address to their website:

我目前有客户的地址。我想要做的是将地址提交到一个流行的在线地图网站,并获取该地区的小地图。我几乎可以使用谷歌地图的嵌入式链接功能来做到这一点。将地址添加到他们的网站后,我可以获得以下 HTML:

<iframe width="300" height="300" frameborder="0" scrolling="no" 
   marginheight="0" marginwidth="0" 
   src="http://maps.google.com/maps?hl=en&amp;ie=UTF8&amp;t=h&amp;g=1193+Presque+Isle+Dr,+Port+Charlotte,+FL+33952&amp;s=AARTsJqsWtjYwJ7ucpVS6UU2EInkRk6JLA&amp;ll=27.012108,-82.087955&amp;spn=0.005735,0.006437&amp;z=16&amp;output=embed">
</iframe>

My first plan was to simply parse this HTML and insert whichever customer's address was needed in place this address, then show the result in a browser object on the form. However, if I change the address in the above iframe Google gives me a "Your client does not have permission to get URL ..." message.

我的第一个计划是简单地解析这个 HTML 并插入任何需要的客户地址来代替这个地址,然后在表单上的浏览器对象中显示结果。但是,如果我更改上述 iframe 中的地址,Google 会给我一条“您的客户无权获取 URL ...”消息。

I have no preference on which map service I ultimately use, the important thing is that the solution can't have an associated expenses and its usable from Windows forms.

我对最终使用的地图服务没有偏好,重要的是该解决方案不能有相关费用,并且可以从 Windows 表单中使用。

Anyone got an ideas/recommendations/resources on how to tackle this?

任何人都有关于如何解决这个问题的想法/建议/资源?

Results:

结果

I ended up using the control found here. I find it an "okay" solution... it's tedious to get working as the code does not work as-is. I'm pretty stunned to find that none of the popular map APIs support winforms.

我最终使用了此处找到的控件。我发现这是一个“不错”的解决方案......因为代码不能按原样工作,所以开始工作很乏味。我很惊讶地发现没有一个流行的地图 API 支持 winform。

采纳答案by Stever B

Both Google Maps and Live Maps have a public api.

Google Maps 和 Live Maps 都有一个公共 API。

Since you are doing winforms I'd probably use live maps.

既然你在做 winforms,我可能会使用实时地图。

http://dev.live.com/VirtualEarth/

http://dev.live.com/VirtualEarth/

There are a few examples on CodePlex.

CodePlex 上有一些示例。

http://codeplex.com/Project/ProjectDirectory.aspx?TagName=Virtual%20Earth

http://codeplex.com/Project/ProjectDirectory.aspx?TagName=Virtual%20Earth

回答by Rowland Shaw

There is some example codefor developing a map viewer control (NB: I doubt this is strictly within their licence)

一些用于开发地图查看器控件的示例代码(注意:我怀疑这是否严格在他们的许可范围内)

Otherwise, depending on your budget, you could use the MapPoint ActiveX control

否则,根据您的预算,您可以使用MapPoint ActiveX 控件

回答by PolicyWatcher

Just use the value inside the src="" as the location for a WebBrowser control directly, without the IFRAME.

只需直接使用 src="" 中的值作为 WebBrowser 控件的位置,无需 IFRAME。

OR

或者

Build a minimal html document wrapping the IFRAME, write it out to a MemoryStream, re-seek it back to the start, and use the MemoryStream to set the WebBrowser control's DocumentStream property.

构建一个包装 IFRAME 的最小 html 文档,将其写出到 MemoryStream,重新寻找它回到起点,并使用 MemoryStream 设置 WebBrowser 控件的 DocumentStream 属性。

PW

私服