如何确定点之间的纬度和经度Gmap.net C#

时间:2017-01-05 08:30:18

标签: c# google-maps polygon gmap.net

我的"BBB"(figure1,figure2)中有一个名为GMap .Net Windows form Application的路径/多边形。我正在从鼠标绘制路径/多边形并将所有纬度和经度存储到List<PointLatLng>。我想要的是设置的两个交叉点(纬度和经度)之间的纬度和经度。

  

注意:   我有所有纬度和经度的路线/多边形"BBB"(figure1,figure2)以及"CCC"(figure1,figure2)

如果不清楚,请告诉我。是否有图书馆或Api?

代码:一些想法代码

    List<PointLatLng> ListOfDragLatLang = new List<PointLatLng>();
    PointLatLng StartingLatLng = new PointLatLng();
    PointLatLng EndingLatLng = new PointLatLng();
   // polygons
    GMapPolygon polygon;

    readonly GMapOverlay top = new GMapOverlay();
    internal readonly GMapOverlay objects = new GMapOverlay("objects");//for storing markers 
    internal readonly GMapOverlay routes = new GMapOverlay("routes");// for storing routes
    internal readonly GMapOverlay polygons = new GMapOverlay("polygons");//for storing polygons

 public bool IsErasorCursorVisible { get => _IsErasorCursorVisible; set => _IsErasorCursorVisible = value; }
    public bool IsPencilCursorVisible { get => _IsPencilCursorVisible; set => _IsPencilCursorVisible = value; }
    public bool IsNormalCursorVisible { get => _IsNormalCursorVisible; set => _IsNormalCursorVisible = value; }
private void MainMap_MouseUp(object sender, MouseEventArgs e)
    {
        PointLatLng OnMouse = MainMap.FromLocalToLatLng(e.X, e.Y);
        lblLatitude.Text = OnMouse.Lat.ToString();
        lblLongitude.Text = OnMouse.Lng.ToString();

            if (IsPencilCursorVisible && IsDrawing)
            {

                EndingLatLng = MainMap.FromLocalToLatLng(e.X, e.Y);
                ListOfDragLatLang.Add(StartingLatLng);
                IsDragging = false;
                IsDrawing = false;
                MainMap.DragButton = MouseButtons.Right;

                //polygon = new GMapPolygon(ListOfDragLatLang, txtZoneName.Text);
                //polygon.LocalPoints.AddRange(ListOfPoints);
                //polygon.Stroke = new Pen(Color.Black, 3);
                //polygon.IsHitTestVisible = true;
                //polygon.Stroke.DashStyle = System.Drawing.Drawing2D.DashStyle.Solid;
                //polygons.Polygons.Add(polygon);
                //MainMap.UpdatePolygonLocalPosition(polygon);
                lblTotalPolygonsAdded.Text = polygons.Polygons.Count.ToString();

                for (int i = 0; i < ListOfDragLatLang.Count; i++)
                {
                        AddPinPointToPolygon(ListOfDragLatLang[i], i, txtZoneName.Text);                        
                }
                RegenerateRoute(txtZoneName.Text);

                GMarkerGoogle marker = new GMarkerGoogle(new PointLatLng(ListOfDragLatLang.Sum(c => c.Lat) / ListOfDragLatLang.Count, ListOfDragLatLang.Sum(c => c.Lng) / ListOfDragLatLang.Count), GMarkerGoogleType.orange_dot);
                marker.ToolTip = new GMapBaloonToolTip(marker);
                marker.ToolTipText = txtZoneName.Text;
                marker.ToolTipMode = MarkerTooltipMode.Always;

                marker.IsVisible = true;
                marker.Tag = txtZoneName.Text;
                objects.Markers.Add(marker);
                MainMap.UpdateMarkerLocalPosition(marker);
                MainMap.UpdatePolygonLocalPosition(polygon);




            }
    }

private void MainMap_MouseDown(object sender, MouseEventArgs e)
    {
        PointLatLng OnMouse = MainMap.FromLocalToLatLng(e.X, e.Y);

        if (e.Button == MouseButtons.Left)
        {
            if (IsPencilCursorVisible && IsDrawing)
            {
                StartingLatLng = OnMouse;
                ListOfDragLatLang.Add(StartingLatLng);
                ListOfPoints.Add(new GPoint(e.X, e.Y));
                IsDragging = true;
                MainMap.DragButton = MouseButtons.Middle;

                currentRoute = new GMapRoute(txtZoneName.Text);
                currentRoute.Stroke = new Pen(Color.Black, 3);
                currentRoute.IsHitTestVisible = true;
                routes.Routes.Add(currentRoute);
                MainMap.UpdateRouteLocalPosition(currentRoute);
                //polygon = new GMapPolygon(ListOfDragLatLang,txtZoneName.Text);
                //polygon.LocalPoints.AddRange(ListOfPoints);
                //polygon.Stroke = new Pen(Color.Black, 3);
                //polygon.IsHitTestVisible = true;
                //polygon.Stroke.DashStyle = System.Drawing.Drawing2D.DashStyle.Solid;
                //polygons.Polygons.Add(polygon);
                //MainMap.UpdatePolygonLocalPosition(polygon);

            }

        }


    }

    private void MainMap_MouseMove(object sender, MouseEventArgs e)
    {
        PointLatLng OnMouse = MainMap.FromLocalToLatLng(e.X, e.Y);

        lblLatitude.Text = OnMouse.Lat.ToString();
        lblLongitude.Text = OnMouse.Lng.ToString();

        if (e.Button == MouseButtons.Left)
        {
            if (IsPencilCursorVisible && IsDrawing)
            {


                if (MainMap.IsMouseOverPolygon)
                {
                    MainMap.Cursor = MainCursor;
                }
                else
                {
                    MainMap.Cursor = PencilCursor;
                }
                IsDragging = true;
                ListOfPoints.Add(new GPoint(e.X, e.Y));
                ListOfDragLatLang.Add(OnMouse);
                lblTotalLatLng.Text = ListOfDragLatLang.Count.ToString();
                currentRoute.Points.Add(OnMouse);
                MainMap.UpdateRouteLocalPosition(currentRoute);
                //polygon.Points.Add(OnMouse);
                //MainMap.UpdatePolygonLocalPosition(polygon);


            }
            else
            {
                PointLatLng pnew = MainMap.FromLocalToLatLng(e.X, e.Y);

                if (CurentRectMarker == null)
                {
                    return;
                }

                int? pIndex = (int?)CurentRectMarker.Tag;
                if (pIndex.HasValue)
                {

                    if (pIndex < currentRoute.Points.Count)
                    {
                        currentRoute.Points[pIndex.Value] = pnew;
                        MainMap.UpdateRouteLocalPosition(currentRoute);
                    }
                    //if (pIndex < polygon.Points.Count)
                    //{
                    //    polygon.Points[pIndex.Value] = pnew;
                    //    MainMap.UpdatePolygonLocalPosition(polygon);
                    //}
                }

                if (currentMarker.IsVisible)
                {
                    currentMarker.Position = pnew;
                }
                CurentRectMarker.Position = pnew;

                if (CurentRectMarker.InnerMarker != null)
                {
                    CurentRectMarker.InnerMarker.Position = pnew;
                }

            }
            MainMap.Refresh();

        }
    }

图1

enter image description here

图2 enter image description here

问题:如何在交叉点yellow color edge"A"之间获得图2中"B"的纬度和经度?

1 个答案:

答案 0 :(得分:0)

假设您的列表的顺序正确

在列表中的A点和B点找到坐标的索引,然后使用两个索引之间的所有点创建一个新列表。