GMap.Net标记最初是在不正确的位置 [英] GMap.Net marker initially in incorrect position

查看:1786
本文介绍了GMap.Net标记最初是在不正确的位置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我添加使用GMAP同纬度/长指定的标记。当应用程序启动时,标志被放置在不正确的位置(在GMAP控制中心),然后当我放大,它然后去指定的坐标。这是在GMAP或错误我做错了什么?这里是代码。

  GMapOverlay markersOverlay,曼达拉; 
GMarkerGoogle标记,marker5;


GMapOverlay polyOverlay;
名单,LT; PointLatLng>点;
GMapRoute克;
图形克;
BOOL启动= TRUE;
双动= 0.0001;
//双动= 1;
双LT = 73,LG = -180;
//双LT = 29,LG = -93;





公共Form1中()
{
AllocConsole();
的InitializeComponent();

{
System.Net.IPHostEntry E =
System.Net.Dns.GetHostEntry(www.google.com);
}

{
gmap.Manager.Mode = AccessMode.CacheOnly;
MessageBox.Show(没有互联网连接avaible,去CacheOnly模式,
GMap.NET - Demo.WindowsForms,M​​essageBoxButtons.OK,
MessageBoxIcon.Warning);
}

gmap.MapProvider = GMapProviders.BingHybridMap;
gmap.Position =新PointLatLng(32,-100);
gmap.MinZoom = 3;
gmap.MaxZoom = 15;
gmap.Zoom = 9;

markersOverlay =新GMapOverlay(标记);
曼达拉=新GMapOverlay(markers5);
marker5 =新GMarkerGoogle(新PointLatLng(A4,B4),
GMarkerGoogleType.orange_small);



G = this.CreateGraphics();






}



私人无效Form1_Load的(对象发件人,EventArgs五)
{

gmap.DragButton = MouseButtons.Left;
gmap.ShowCenter = FALSE;
点=新的List< PointLatLng>();
polyOverlay =新GMapOverlay(多边形);
// gmap.Position =新PointLatLng(32.6961334816182,-100.2985095977783);
// gmap.MinZoom = 0;

GMapPolygon多边形=新GMapPolygon(点mypolygon);
polygon.Fill =新SolidBrush(Color.FromArgb(50 Color.Magenta));
// polygon.f
polygon.Stroke =新朋(Color.Magenta,2);







}
保护无效的OnMouseMove(对象发件人,MouseEventArgs E)
{
// base.OnMouseMove(E);
PointLatLng P = gmap.FromLocalToLatLng(e.X,e.Y);
MouseLatLong.Text = Convert.ToString(对);
// Console.WriteLine(marker.Position.Lat);
}

私人无效SubmitButton_Click(对象发件人,EventArgs五)
{
// gmap.Position =新PointLatLng(40.6961334816182,-100.2985095977783);


标记=新GMarkerGoogle(新PointLatLng(double.Parse(LattextBox.Text),double.Parse(LongtextBox.Text)),
新位图(@C: \Users\Vaib\Documents\Visual工作室2013\Projects\testGmap\testGmap\Resources\wpt.png));
// GMarkerGoogle标记=新GMarkerGoogle(新PointLatLng(-25.966688,32.580528),旗);
mo2.Markers.Add(标记);
gmap.Overlays.Add(MO 2);
marker.ToolTip =新GMapToolTip(标记);
marker.ToolTipText = NametextBox.Text;
marker.ToolTipMode = MarkerTooltipMode.Always;

// X ++;
如果(开始)
{
gmap.Position =新PointLatLng(marker.Position.Lat,marker.Position.Lng);
开始= FALSE;

}



points.Add(新PointLatLng(marker.Position.Lat,marker.Position.Lng));
// points.Add(新PointLatLng(double.Parse(LattextBox.Text),double.Parse(LongtextBox.Text)));

// GMapPolygon多边形=新GMapPolygon(点mypolygon);
GR =新GMapRoute(点,路线);
gr.Stroke =新朋(Color.Magenta,2);
//Console.WriteLine(gr.From + - >中+ gr.To);
// polygon.Stroke =新朋(Color.Magenta,2);
polyOverlay.Routes.Add(克);
gmap.Overlays.Add(polyOverlay);

// M1 =新GMarkerGoogle(新PointLatLng(gr.From.Value.Lat,gr.From.Value.Lng),
//GMarkerGoogleType.yellow_small);
GA =新GMarkerArrow(新PointLatLng(gr.From.Value.Lat,gr.From.Value.Lng));
如果(points.Count> = 2)
ga.Bearing =(浮点)决赛(gr.From.Value.Lat,gr.From.Value.Lng,点[1] .Lat,点[1] .Lng);
// MARKER2 =新GMapMarkerImage(新PointLatLng(marker.Position.Lat,marker.Position.Lng),

markersOverlay.Clear();
//m1.rot (180);
// m1.OnRender(G);
// markersOverlay.Markers.Add(MARKER2);
markersOverlay.Markers.Add(GA);
GMAP .Overlays.Add(markersOverlay);






}


解决方案

诀窍是先加覆盖,然后标记:



gMapControl.Overlays.Add(markersOverlay);
markersOverlay.Markers.Add(标记);


I have added a marker using GMap with the lat/long specified. When the application starts, the marker is placed in the incorrect position(at the center of the GMap control) and then when I zoom, it then goes to the specified coordinates. Is this a bug in GMap or am I doing something wrong? Here is the code.

    GMapOverlay markersOverlay, mo2;
    GMarkerGoogle marker, marker5;


    GMapOverlay polyOverlay;
    List<PointLatLng> points;
    GMapRoute gr;
    Graphics g;
    bool start = true;
    double move = .0001;
    //double move = 1;
    double lt = 73, lg = -180;
    //  double lt = 29, lg = -93;





    public Form1()
    {
        AllocConsole();
        InitializeComponent();
        try
        {
            System.Net.IPHostEntry e =
                 System.Net.Dns.GetHostEntry("www.google.com");
        }
        catch
        {
            gmap.Manager.Mode = AccessMode.CacheOnly;
            MessageBox.Show("No internet connection avaible, going to CacheOnly mode.",
                  "GMap.NET - Demo.WindowsForms", MessageBoxButtons.OK,
                  MessageBoxIcon.Warning);
        }

        gmap.MapProvider = GMapProviders.BingHybridMap;
        gmap.Position = new PointLatLng(32, -100);
        gmap.MinZoom = 3;
        gmap.MaxZoom = 15;
        gmap.Zoom = 9;

        markersOverlay = new GMapOverlay("markers");
        mo2 = new GMapOverlay("markers5");
        marker5 = new GMarkerGoogle(new PointLatLng(lt, lg),
         GMarkerGoogleType.orange_small);



        g = this.CreateGraphics();






    }



    private void Form1_Load(object sender, EventArgs e)
    {

        gmap.DragButton = MouseButtons.Left;
        gmap.ShowCenter = false;
        points = new List<PointLatLng>();
        polyOverlay = new GMapOverlay("polygons");
        // gmap.Position = new PointLatLng(32.6961334816182, -100.2985095977783);
        //   gmap.MinZoom = 0;

        GMapPolygon polygon = new GMapPolygon(points, "mypolygon");
        polygon.Fill = new SolidBrush(Color.FromArgb(50, Color.Magenta));
        // polygon.f
        polygon.Stroke = new Pen(Color.Magenta, 2);







    }
    protected void OnMouseMove(object sender, MouseEventArgs e)
    {
        // base.OnMouseMove(e);
        PointLatLng p = gmap.FromLocalToLatLng(e.X, e.Y);
        MouseLatLong.Text = Convert.ToString(p);
        // Console.WriteLine(marker.Position.Lat);
    }

    private void SubmitButton_Click(object sender, EventArgs e)
    {
        //  gmap.Position = new PointLatLng(40.6961334816182, -100.2985095977783);


        marker = new GMarkerGoogle(new PointLatLng(double.Parse(LattextBox.Text), double.Parse(LongtextBox.Text)),
         new Bitmap(@"C:\Users\Vaib\Documents\Visual Studio 2013\Projects\testGmap\testGmap\Resources\wpt.png"));
        // GMarkerGoogle marker = new GMarkerGoogle(new PointLatLng(-25.966688, 32.580528),flag);
        mo2.Markers.Add(marker);
        gmap.Overlays.Add(mo2);
        marker.ToolTip = new GMapToolTip(marker);
        marker.ToolTipText = NametextBox.Text;
        marker.ToolTipMode = MarkerTooltipMode.Always;

        //  x++;
        if (start)
        {
            gmap.Position = new PointLatLng(marker.Position.Lat, marker.Position.Lng);
            start = false;

        }



        points.Add(new PointLatLng(marker.Position.Lat, marker.Position.Lng));
        // points.Add(new PointLatLng(double.Parse(LattextBox.Text), double.Parse(LongtextBox.Text)));

        // GMapPolygon polygon = new GMapPolygon(points, "mypolygon");
        gr = new GMapRoute(points, "route");
        gr.Stroke = new Pen(Color.Magenta, 2);
        //Console.WriteLine(gr.From + "-->"+gr.To);
        // polygon.Stroke = new Pen(Color.Magenta, 2);
        polyOverlay.Routes.Add(gr);
        gmap.Overlays.Add(polyOverlay);

        //  m1 = new GMarkerGoogle(new PointLatLng(gr.From.Value.Lat, gr.From.Value.Lng),
        //GMarkerGoogleType.yellow_small);
        ga = new GMarkerArrow(new PointLatLng(gr.From.Value.Lat, gr.From.Value.Lng));
        if (points.Count >= 2)
            ga.Bearing = (float)final(gr.From.Value.Lat, gr.From.Value.Lng, points[1].Lat, points[1].Lng);
        //         marker2 = new GMapMarkerImage(new PointLatLng(marker.Position.Lat, marker.Position.Lng),

        markersOverlay.Clear();
        //m1.rot(180);
        // m1.OnRender(g);
        //  markersOverlay.Markers.Add(marker2);
        markersOverlay.Markers.Add(ga);
        gmap.Overlays.Add(markersOverlay);






    }

解决方案

The trick is to first add overlay and then the marker:

gMapControl.Overlays.Add(markersOverlay); markersOverlay.Markers.Add(marker);

这篇关于GMap.Net标记最初是在不正确的位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆