问题描述
我需要有关c#桌面应用程序的帮助。如何在不使用api的情况下在c#桌面应用程序的Webbrowser控件中显示google Earth(从datagridview中的纬度和经时选择)。
解决方法
先决条件:CefSharp.WinForms
通过Nuget,引用为Cefsharp。请注意,使用默认的webBrowser控件时存在一些限制,这就是为什么我为此使用 Cefsharp 的原因。您可以阅读这篇文章C# webBrowser script error。
关于Fun stuff to do with the new Google Earth URL的文章。
private const string googleEarthUrl = "https://earth.google.com/web/@{0},{1},{2}a,{3}d";
private ChromiumWebBrowser browser;
private decimal locationAltitude = 200;
private decimal distanceOfEyeFromThePoint = 500000;
初始化
browser = new ChromiumWebBrowser(getLocationUrl());
gbGoogleEarth.Controls.Add(browser);
获取位置网址
private string getLocationUrl()
{
return string.Format(googleEarthUrl,txtLatitude.Text,txtLongitude.Text,distanceOfEyeFromThePoint,locationAltitude);
}
提交
browser.Load(getLocationUrl());