2016-06-24 7 views
0

Ich möchte alle meine Markierungen auf der Google Map anzeigen. Ich verwende die Komponente Google map sdk aus dem Komponentenspeicher. Ich kann eine einzelne Markierung gut zeigen. Aber ich möchte alle Markierungen anzeigen, die ich in einer Liste habe. Ich fand Lösungen, die vorschlugen, GMSCoordinateBounds zu verwenden, aber ich konnte es nicht mit dem sdk finden, das ich verwende. Ich weiß, dass ich die CameraUpdate.FitBounds() verwenden muss.Alle Markierungen mit Google Karte anzeigen sdk iOS Xamarin

Ich habe den folgenden Code implementiert, aber dieser zeigt nur den letzten Marker in der Liste.

private float CalculateMarkerInclusiveZoomLevel(MapView mapView, List<Marker> markers, int minVisible) 
     { 
      try 
      { 
       var bounds = 
        new CoordinateBounds(mapView.Projection.VisibleRegion); 
       var initialZoomLevel = mapView.Camera.Zoom; 
       markerInclusiveZoomLevel = initialZoomLevel; 
      var count = markers.Count(
       m => bounds.ContainsCoordinate(m.Position)); 

      while (count < markers.Count && count < minVisible) 
      { 
       // Each zoom level doubles the viewable area 
       var latGrowth = 
        (bounds.NorthEast.Latitude - bounds.SouthWest.Latitude)/2; 
       var lngGrowth = 
        (bounds.NorthEast.Longitude - bounds.SouthWest.Longitude)/2; 
       markerInclusiveZoomLevel--; 

       bounds = new CoordinateBounds(
        new CLLocationCoordinate2D(
         bounds.NorthEast.Latitude + latGrowth, 
         bounds.NorthEast.Longitude + lngGrowth), 
        new CLLocationCoordinate2D(
         bounds.SouthWest.Latitude - latGrowth, 
         bounds.SouthWest.Longitude - lngGrowth)); 

       count = markers.Count(m => bounds.ContainsCoordinate(m.Position)); 
       return markerInclusiveZoomLevel; 
      } 

     } 
     catch (Exception ex) 
     { 

     } 

     return markerInclusiveZoomLevel; 
    } 

Wie mache ich es. Jedes Beispiel wird nützlich sein.

Antwort

1

Hier wird jedoch nur der letzte Marker in der Liste angezeigt.

Nun ja. In Ihrer while-Schleife geben Sie die endgültige Anweisung zurück.

Wahrscheinlich möchten Sie diese Rückgabeanweisung aus Ihrer while-Schleife entfernen. Also:

private float CalculateMarkerInclusiveZoomLevel(MapView mapView, List<Marker> markers, int minVisible) 
{ 
    try 
    { 
     var bounds = new CoordinateBounds(mapView.Projection.VisibleRegion); 
     var initialZoomLevel = mapView.Camera.Zoom; 
     markerInclusiveZoomLevel = initialZoomLevel; 
     var count = markers.Count(m => bounds.ContainsCoordinate(m.Position)); 

     while (count < markers.Count && count < minVisible) 
     { 
      // Each zoom level doubles the viewable area 
      var latGrowth = 
       (bounds.NorthEast.Latitude - bounds.SouthWest.Latitude)/2; 
      var lngGrowth = 
       (bounds.NorthEast.Longitude - bounds.SouthWest.Longitude)/2; 
      markerInclusiveZoomLevel--; 

      bounds = new CoordinateBounds(
       new CLLocationCoordinate2D(
        bounds.NorthEast.Latitude + latGrowth, 
        bounds.NorthEast.Longitude + lngGrowth), 
       new CLLocationCoordinate2D(
        bounds.SouthWest.Latitude - latGrowth, 
        bounds.SouthWest.Longitude - lngGrowth)); 

      count = markers.Count(m => bounds.ContainsCoordinate(m.Position)); 
     } 
     return markerInclusiveZoomLevel; 
    } 
    catch (Exception ex) 
    { 

    } 
    return markerInclusiveZoomLevel; 
} 
+0

Hallo, habe ich versucht, das gleiche zunächst, aber die Rückkehr Aussage wird nie erreicht. –

Verwandte Themen