【发布时间】:2020-07-09 14:13:56
【问题描述】:
我在一个使用 Xamarin Forms 和 OpenStreetMap 的项目中。 我正在尝试获取地图中心的坐标。
这是我创建地图的代码
public static Map CreateMap(double latitud, double longitud)
{
map = new Map();
var location = new Point(longitud, latitud);
var sphericalMercatorCoordinate = SphericalMercator.FromLonLat(location.X, location.Y);
map.Layers.Add(OpenStreetMap.CreateTileLayer());
map.Home = n => n.NavigateTo(sphericalMercatorCoordinate, map.Resolutions[15]);
return map;
}
这是我在文件 xaml 中的代码。
<maps:MapView x:Name="MapView"
TouchMove="MapView_TouchMove"
MyLocationFollow="True"
IsMyLocationButtonVisible="False"
VerticalOptions="FillAndExpand"
HorizontalOptions="FillAndExpand" />
尝试添加方法“TouchMove”。但只得到地图的边界而不是坐标。
private void MapView_TouchMove(object sender, Mapsui.UI.TouchedEventArgs e)
{
var center = MapView.Bounds.Center;
}
所以,尝试添加一个 MapClicked 方法,用于从“MapView_TouchMove”调用此方法,但我不知道如何调用。
private void MapView_MapClicked(object sender, MapClickedEventArgs e)
{
var lat = e.Point.Latitude;
}
任何想法..??? 谢谢。
【问题讨论】:
-
如果您链接到您正在使用的实际地图控件会很有帮助
-
添加了我创建地图的代码。我使用 OpenStreetMap
-
我知道您正在使用 OpenStreetMap。我假设您正在使用一些 Nuget 包作为控件,我要求您提供指向它的链接
-
github.com/Mapsui/Mapsui - 谢谢..!!
标签: android ios xamarin xamarin.forms openstreetmap