dal*_*on5 1 maps nettopologysuite xamarin.forms entity-framework-core
我开发了一个 xamarin 表单应用程序,我将一些地方存储在我的数据库中。我使用具有纬度和经度的 efcore 存储 Location NetTopology 套件。然后我可以从地图上的一个点找到最近的地方。
但是,如果我移动地图或缩小地图,我如何才能找到存储在我的数据库中的新区域中的地点以将它们固定在地图上?
有例子吗?
我真的很难找到一种方法来说明我数据库中的这个地点列表是地图显示内容的一部分。
我使用 xamarin 地图。
谢谢
为此,您需要找到地图可见区域的边界。让我解释一下。
绑定类:
public class Bounds
{
public double South { get; set; }
public double West { get; set; }
public double North { get; set; }
public double East { get; set; }
}
Run Code Online (Sandbox Code Playgroud)
地图有一个叫做可见区域的属性。当地图的属性发生变化时,地图的可见区域也会发生变化。下面是地图类:
Bounds bounds = new Bounds();
customMap.PropertyChanged += (sender, e) =>
{
Debug.WriteLine(e.PropertyName + " just changed!");
if (e.PropertyName == "VisibleRegion" && customMap.VisibleRegion != null)
CalculateBoundingCoordinates(customMap.VisibleRegion);
};
static void CalculateBoundingCoordinates(MapSpan region)
{
try
{
_region = region;
var center = region.Center;
var halfheightDegrees = region.LatitudeDegrees / 2;
var halfwidthDegrees = region.LongitudeDegrees / 2;
var left = center.Longitude - halfwidthDegrees;
var right = center.Longitude + halfwidthDegrees;
var top = center.Latitude + halfheightDegrees;
var bottom = center.Latitude - halfheightDegrees;
if (left < -180) left = 180 + (180 + left);
if (right > 180) right = (right - 180) - 180;
bounds.West = left;
bounds.East = right;
bounds.North = top;
bounds.South = bottom;
}
}
Run Code Online (Sandbox Code Playgroud)
现在使用这些边界查询您的数据库。
| 归档时间: |
|
| 查看次数: |
792 次 |
| 最近记录: |