0
我想在Google Map上顯示我所有的標記。我正在使用組件商店中的Google map sdk
組件。我可以顯示一個標記。但是我想顯示列表中的所有標記。我確實找到了建議使用GMSCoordinateBounds
的解決方案,但我無法使用我正在使用的sdk找到它。我知道我必須使用CameraUpdate.FitBounds()
。用Google Map sdk顯示所有標記iOS Xamarin
我已經實現了下面的代碼,但是這隻顯示列表中的最後一個標記。
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;
}
我該怎麼做。任何示例都會有用。
嗨,我試着做同樣的最初,但回報聲明永遠不會達成。 –