如何导入/导出kml并在gmap.net中显示

时间:2018-04-14 11:08:39

标签: c# visual-studio kml gmap.net

我想使用Microsoft Visual Studio和GMaps.NET创建一个简单的数据库查看器,它可以(1)执行特定搜索并更新列表,(2)将列表导出为KML,以及(3)上传KML文件在嵌入式gmap中查看。第1步已经解决但我找不到参考继续执行第2步和第3步。任何帮助都将受到高度赞赏!

这是我的代码:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using GMap.NET;
using GMap.NET.WindowsForms;
using GMap.NET.WindowsForms.Markers;
using GMap.NET.MapProviders;
//if these GMap statements are not enabled, these will have to be typed with the namespaces e.g. GMap.Net.MapProviders.GoogleMap
namespace KDMI_DBViewer_v1._0
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void existingPermitsBindingNavigatorSaveItem_Click(object sender, EventArgs e)
        {
            this.Validate();
            this.existingPermitsBindingSource.EndEdit();
            this.tableAdapterManager.UpdateAll(this.permits_2016DataSet);

        }

        private void Form1_Load(object sender, EventArgs e)
        {
            // TODO: This line of code loads data into the 'permits_2016DataSet.ExistingPermits' table. You can move, or remove it, as needed.
            this.existingPermitsTableAdapter.Fill(this.permits_2016DataSet.ExistingPermits);
        }

        private void gMapControl1_Load(object sender, EventArgs e)
        {
            gMapControl1.MapProvider = GMapProviders.GoogleTerrainMap;
            //gMapControl1.ShowCenter = false; if enabled, this will remove the red cross
            gMapControl1.Position = new PointLatLng(12.0725555, 122.895494);
            gMapControl1.DragButton = MouseButtons.Left;
            gMapControl1.Zoom = 5;
            gMapControl1.MinZoom = 5;
            gMapControl1.MaxZoom = 12;

        }


        private void specificSearchToolStripButton_Click(object sender, EventArgs e)
        {
            try
            {
                this.existingPermitsTableAdapter.SpecificSearch(this.permits_2016DataSet.ExistingPermits, provinceToolStripTextBox.Text, municipalityToolStripTextBox.Text, typeToolStripTextBox.Text);
            }
            catch (System.Exception ex)
            {
                System.Windows.Forms.MessageBox.Show(ex.Message);
            }

        }

1 个答案:

答案 0 :(得分:0)

不幸的是,作为GMap.Net的创建者,还没有实现KML解析器gmap.net issues

但您可以使用名为SharpKML

的库自行创建导入 \ 导出 KML \ KMZ方法
  

SharpKML 是Open Geospatial Consortium(OGC)的一项实施   用C#开发的KML 2.2标准,能够读/写两个KML文件   和KMZ文件

使用入门:

  

使用该库的最简单方法是安装 SharpKml.Core NuGet package ,但是,您也可以下载二进制文件/源代码   来自这个项目页面。