首先需要安装geoserver,并且发布了自己的本地数据,或者用它自带的数据也行。
安装google earth,新建项目,在引用中添加对google earth com api的引用EARTHLib,代码如下:
private void someevent(object sender, EventArgs e)
{
string uri = "http://localhost:8888/geoserver/wms?bbox=-130,24,-66,50&styles=population&Format=kml&request=GetMap&layers=topp:states&width=550&height=250&srs=EPSG:4326";
System.Net.WebRequest wr = System.Net.WebRequest.Create(uri);
IApplicationGE wmsget = appGE as IApplicationGE;
using (System.Net.WebResponse response = wr.GetResponse())
{
Encoding encode = System.Text.Encoding.GetEncoding("utf-8");
StreamReader readStream = new StreamReader(response.GetResponseStream(), encode);
string kml = readStream.ReadToEnd();
wmsget.LoadKmlData(ref kml);
}
}