gpt4 book ai didi

ios - 使用 Google Map sdk iOS Xamarin 显示所有标记

转载 作者:行者123 更新时间:2023-11-29 00:52:10 26 4
gpt4 key购买 nike

我想在 Google map 上显示我所有的标记。我正在使用组件商店中的 Google map sdk 组件。我可以很好地显示单个标记。但我想显示列表中的所有标记。我确实找到了建议使用 GMSCoordinateBounds 的解决方案,但我无法在我使用的 sdk 中找到它。我知道我必须使用 CameraUpdate.FitBounds()

我已经实现了下面的代码,但这只显示了列表中的最后一个标记。

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;
}

我该怎么做。任何示例都会很有用。

最佳答案

but this only shows the last marker in the list only.

嗯,是的。在 while 循环中,您将作为最终语句返回。

您可能希望将该 return 语句移出 while 循环。所以:

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;
}

关于ios - 使用 Google Map sdk iOS Xamarin 显示所有标记,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38006856/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com