2017-07-06 88 views
0
string lat = "40.682640,40.682671,40.682701,40.682732,40.682763,40.682794"; 
string lng = "-73.868470,-73.868359,-73.868247,-73.868136,-73.868025,-73.867913"; 
int index = 0; 
private void Form1_Load(object sender, EventArgs e) 
{ 
    Timer MyTimer = new Timer(); 
    MyTimer.Interval = (2000); 
    MyTimer.Tick += new EventHandler(MyTimer_Tick); 
    MyTimer.Start(); 
} 
private void MyTimer_Tick(object sender, EventArgs e) 
{ 

    string[] Latitude = lat.Split(','); 
    string[] Longitude = lng.Split(','); 

    gmap.MapProvider = GMap.NET.MapProviders.BingMapProvider.Instance; 
    GMap.NET.GMaps.Instance.Mode = GMap.NET.AccessMode.ServerOnly; 
    GMapProvider.WebProxy = null; 
    gmap.SetPositionByKeywords("Atlantic Ave,USA"); 
    gmap.Position = new GMap.NET.PointLatLng(40.683377, -73.865798); 
    gmap.ShowCenter = false; 
    GMapOverlay markers = new GMapOverlay("markers"); 
    GMapMarker marker = new GMarkerGoogle(new PointLatLng(float.Parse(Latitude[index]), float.Parse(Longitude[index])), GMarkerGoogleType.blue); 

    gmap.Overlays.Add(markers); 
    markers.Markers.Add(marker); 
    index++; 

    GMapMarker marker1 = new GMarkerGoogle(new PointLatLng(40.684175, -73.862904), GMarkerGoogleType.green); 

    markers.Markers.Add(marker1); 
} 

用戶移動我需要一個標誌更新其位置(藍色標記)隨着用戶移動,而另一標記保持靜止位置。我試過markers.Markers.remove(marker);,但所有標記都被刪除。我怎樣才能得到一個單一的標記,以更新它在GMap.net

回答

0

,我得到了一個標記更新其位置,當我宣佈MyTimer_Tick方法

string lat = "40.682640,40.682671,40.682701,40.682732,40.682763,40.682794,40.682824,40.682855,40.682886,40.682916,40.682947,40.682978,40.683008,40.683039,40.683070,40.683101,40.683131,40.683162,40.683193,40.683223,40.683254,40.683285,40.683316,40.683346,40.683377,40.683408,40.683438,40.683469,40.683500,40.683530,40.683561,40.683592,40.683623,40.683653,40.683684,40.683715,40.683745,40.683776,40.683807,40.683838,40.683868,40.683899,40.683930,40.683960,40.683991,40.684022,40.684053,40.684083,40.684114,40.684145,40.684175"; 
    string lng = "-73.868470,-73.868359,-73.868247,-73.868136,-73.868025,-73.867913,-73.867802,-73.867691,-73.867579,-73.867468,-73.867357,-73.867246,-73.867134,-73.867023,-73.866912,-73.866800,-73.866689,-73.866578,-73.866466,-73.866355,-73.866244,-73.866132,-73.866021,-73.865910,-73.865798,-73.865687,-73.865576,-73.865464,-73.865353,-73.865242,-73.865130,-73.865019,-73.864908,-73.864797,-73.864685,-73.864574,-73.864463,-73.864351,-73.864240,-73.864129,-73.864017,-73.863906,-73.863795,-73.863683,-73.863572,-73.863461,-73.863349,-73.863238,-73.863127,-73.863015,-73.862904"; 
    int index = 0; 

    GMapOverlay markers = new GMapOverlay("markers"); 
    GMapMarker marker = new GMarkerGoogle(new PointLatLng(40.682640, -73.868470), GMarkerGoogleType.blue); 

    public Form2() 
    { 
     InitializeComponent(); 
    } 

    private void Form2_Load(object sender, EventArgs e) 
    { 
     System.Windows.Forms.Timer MyTimer = new System.Windows.Forms.Timer(); 
     MyTimer.Interval = (1000); 
     MyTimer.Tick += new EventHandler(MyTimer_Tick); 
     MyTimer.Start(); //calling the timer 
    } 

    private void MyTimer_Tick(object sender, EventArgs e) 
    { 
     //adding google map 
     string[] Latitude = lat.Split(','); 
     string[] Longitude = lng.Split(','); 
     gmap.MapProvider = BingMapProvider.Instance; 
     GMaps.Instance.Mode = GMap.NET.AccessMode.ServerOnly; 
     GMapProvider.WebProxy = null; 
     gmap.SetPositionByKeywords("Atlantic Ave,USA"); 
     gmap.Position = new GMap.NET.PointLatLng(40.683377, -73.865798); 
     gmap.ShowCenter = false; 
     gmap.Overlays.Add(markers); 
     markers.Markers.Add(marker); //adding the blue marker 
     index++; 
     marker.Position = new PointLatLng(float.Parse(Latitude[index]), float.Parse(Longitude[index])); 
     GMapMarker marker1 = new GMarkerGoogle(new PointLatLng(40.684175, -73.862904), GMarkerGoogleType.green); 
     markers.Markers.Add(marker1); //adding the green marker 
    } 

外的標記但地圖每隔幾秒就會重新渲染。是否有任何方法可以下載地圖並將其脫機使用,以避免重繪地圖。

0

按照source code,像下面應該更新的位置:從GMapMarker

marker.Position = new PointLatLng(lat, lng); 

GMarkerGoogle繼承具有public PointLatLng Position。的Position設置器,像這樣:

set 
{ 
    if(position != value) 
    { 
     position = value; 
     if(IsVisible) 
     { 
      if(Overlay != null && Overlay.Control != null) 
      { 
       Overlay.Control.UpdateMarkerLocalPosition(this); 
      } 
     } 
    } 
} 

通知的Overlay.Control.UpdateMarkerLocalPosition(this);

+0

我試過了,但沒有工作。標記沒有被更新@Jaun Ferrer – divya

+0

好吧,'UpdateMarkerLocalPosition'前面有三個條件。如果它是可見的,它可以是'Overlay'或'Overlay.Control'爲空。 –

相關問題