2017-03-16 57 views
0

我目前正在使用gmap.net使用多邊形創建特定的半徑。我目前已經爲半徑做了一個多邊形,但是現在我遇到了我想要創建多面體標記的問題,但只顯示了多邊形內的標記。這可能嗎?Gmap.net只顯示多邊​​形內的標記

_polygonOverlay = new GMapOverlay("destination"); 
_gMap.Overlays.Add(_polygonOverlay); 

private void CreateCircle(PointLatLng destination, double radius) 
    { 
     List<PointLatLng> radiusPoint = new List<PointLatLng>(); 

     double seg = Math.PI * 2/40; 

     for (int i = 0; i < 40; i++) 
     { 
      double theta = seg * i; 
      double latitude = destination.Lat + Math.Cos(theta) * radius; 
      double longitude = destination.Lng + Math.Sin(theta) * radius; 

      PointLatLng cirlePoint = new PointLatLng(latitude, longitude); 

      radiusPoint.Add(cirlePoint); 
     } 
     GMapPolygon radiusCircle = new GMapPolygon(radiusPoint, "radius"); 
     _polygonOverlay.Polygons.Add(radiusCircle); 
    } 

private void CreateMarkers() 
     { 
      _polygonOverlay.Markers.Add(new GMarkerGoogle(new PointLatLng(xxx, xxx), GMarkerGoogleType.blue)); 
      _polygonOverlay.Markers.Add(new GMarkerGoogle(new PointLatLng(xxx, xxx), GMarkerGoogleType.blue)); 
      _polygonOverlay.Markers.Add(new GMarkerGoogle(new PointLatLng(xxx, xxx), GMarkerGoogleType.blue)); 
     } 

下面是我創建一個圓的代碼(仍然需要一些工作)和一些標記的小樣本。

由於已經提前是

+0

添加一些代碼。因爲這個問題太廣泛了。 –

+0

添加了一些我希望這有助於理解的代碼 – MrAndre

回答

0

既然你正在處理一個圈,你應該能夠簡單地從圓心檢查標記的距離。如果距離大於半徑,請勿將其添加到疊加層。

GMap可讓您訪問確定此信息的必要方法。做這樣的事情:

//Assuming p1 is your marker and p2 is your circle center coordinate 
double markerDist = GMap.NET.MapProviders.EmptyProvider.Instance.Projection.GetDistance(p1.Position, p2); 

if(markerDist <= circleRadius) 
{ 
    //Add the marker to the overlay 
}