如何在不使用API​​的情况下在C#桌面应用程序中显示Google Earth / Google Map

问题描述

我需要有关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());

样本输出:
enter image description here

相关问答

错误1:Request method ‘DELETE‘ not supported 错误还原:...
错误1:启动docker镜像时报错:Error response from daemon:...
错误1:private field ‘xxx‘ is never assigned 按Alt...
报错如下,通过源不能下载,最后警告pip需升级版本 Requirem...