Android 在Xamarin中,我需要在地图中心设置标记并获得位置
我试图在Xamarin中在地图中心添加一个标记,该标记将是固定的,不能拖动,该标记下的地图可以正常拖动。我需要得到用户选择的地图的位置,我在互联网上搜索了很多,但没有找到任何可以帮助我的东西。此功能在Uber应用程序中广泛使用。在Android 在Xamarin中,我需要在地图中心设置标记并获得位置,android,xamarin,xamarin.ios,xamarin.forms,xamarin.android,Android,Xamarin,Xamarin.ios,Xamarin.forms,Xamarin.android,我试图在Xamarin中在地图中心添加一个标记,该标记将是固定的,不能拖动,该标记下的地图可以正常拖动。我需要得到用户选择的地图的位置,我在互联网上搜索了很多,但没有找到任何可以帮助我的东西。此功能在Uber应用程序中广泛使用。在iOS上,您可以在MKMapViewDelegate子类上使用RegionChanged在用户滚动地图时获取更新。使用MKMapView.Region获取地图视图的中心(CLLocationCoordinate2D) class MyMapDelegate : MKMa
iOS
上,您可以在MKMapViewDelegate
子类上使用RegionChanged
在用户滚动地图时获取更新。使用MKMapView.Region
获取地图视图的中心(CLLocationCoordinate2D
)
class MyMapDelegate : MKMapViewDelegate
{
public override void RegionChanged(MKMapView mapView, bool animated)
{
Console.WriteLine($"{mapView.Region.Center.Latitude} : {mapView.Region.Center.Longitude}");
// Update your map's MKPointAnnotation's Coordinate to match the mapView.Region.Center
}
}
在Android
上,您可以使用GoogleMap.IOnCameraMoveListener
上的OnCameraMove
在用户滚动地图时获取更新。使用谷歌地图.CameraPosition.Target
获取地图视图中心的纵横比,并更新标记选项的位置:
public class MapCameraMoveListener : Java.Lang.Object, GoogleMap.IOnCameraMoveListener
{
readonly GoogleMap googleMap;
public MapCameraMoveListener(GoogleMap googleMap) { this.googleMap = googleMap; }
public void OnCameraMove()
{
Log.Debug("SO", $"{googleMap?.CameraPosition.Target.Latitude} : {googleMap?.CameraPosition.Target.Longitude}");
// Update your map's `MarkerOptions`'s position to match the CameraPosition.Target
}
}
对于Xamarin.Forms
查看有关如何通过自定义渲染器自定义地图以实现上述原生功能的示例:
非常感谢你,我的朋友!我相信这就是我需要的!