如何使用 Xamarin Maps 缩放到边界框?
How do you zoom to bounding box using Xamarin Maps?
我有一张 Xamarin Android 地图 (VS2019) 和一些 lat/long 点。我想要做的是放大(或缩小)地图,给定一组设置边界框的坐标。
我有这段代码(如下),它似乎没有做任何事情。我已经阅读了所有建议它应该工作但没有工作的文档。我已检查并正确设置了边界框坐标,但地图没有任何作用。
根据调用 LayOut
的文档应该使它更新,但它什么也没做,没有错误,什么也没有。
我如何实现这一点,任何帮助将不胜感激。
MyMap.Layout(GetBounds(points));
private Rectangle GetBounds(List<Point> points)
{
var minx = (from x in points select x.X).Min();
var maxx = (from x in points select x.X).Max();
var miny = (from x in points select x.Y).Min();
var maxy = (from x in points select x.Y).Max();
Rectangle rectangle = new Rectangle(minx, miny, maxx - minx, maxy - miny);
return rectangle;
}
这是我所做的
我在需要的地方创建了一个带有边界的矩形
Rectangle rectangle = GetBounds(points);
然后我得到了矩形位置
Position p1 = new Position(rectangle.X, rectangle.Y);
Position p2 = new Position((rectangle.X + rectangle.Width), (rectangle.Y + rectangle.Height));
...然后得到矩形的中心点
double x = rectangle.X + (rectangle.Width / 2);
double y = rectangle.Y + (rectangle.Height / 2);
然后使用该数据调用 .MoveToRegion
,它起作用了
MyMap.MoveToRegion(
MapSpan.FromCenterAndRadius(
new Xamarin.Forms.Maps.Position(x, y), Distance.BetweenPositions(p1, p2))
);
我有一张 Xamarin Android 地图 (VS2019) 和一些 lat/long 点。我想要做的是放大(或缩小)地图,给定一组设置边界框的坐标。
我有这段代码(如下),它似乎没有做任何事情。我已经阅读了所有建议它应该工作但没有工作的文档。我已检查并正确设置了边界框坐标,但地图没有任何作用。
根据调用 LayOut
的文档应该使它更新,但它什么也没做,没有错误,什么也没有。
我如何实现这一点,任何帮助将不胜感激。
MyMap.Layout(GetBounds(points));
private Rectangle GetBounds(List<Point> points)
{
var minx = (from x in points select x.X).Min();
var maxx = (from x in points select x.X).Max();
var miny = (from x in points select x.Y).Min();
var maxy = (from x in points select x.Y).Max();
Rectangle rectangle = new Rectangle(minx, miny, maxx - minx, maxy - miny);
return rectangle;
}
这是我所做的
我在需要的地方创建了一个带有边界的矩形
Rectangle rectangle = GetBounds(points);
然后我得到了矩形位置
Position p1 = new Position(rectangle.X, rectangle.Y);
Position p2 = new Position((rectangle.X + rectangle.Width), (rectangle.Y + rectangle.Height));
...然后得到矩形的中心点
double x = rectangle.X + (rectangle.Width / 2);
double y = rectangle.Y + (rectangle.Height / 2);
然后使用该数据调用 .MoveToRegion
,它起作用了
MyMap.MoveToRegion(
MapSpan.FromCenterAndRadius(
new Xamarin.Forms.Maps.Position(x, y), Distance.BetweenPositions(p1, p2))
);