Xamarin 如何在Xamarn.forms中显示地图的全局视图(三维视图)
我们需要使用Xamarin.Forms在Android、iOS和Windows.UWP的3D地球地图上显示选定的城市。目前我们正在使用Xamarin.Forms.Maps,但它只显示地球的二维地图 我们如何制作地球的3D地图Xamarin 如何在Xamarn.forms中显示地图的全局视图(三维视图),xamarin,xamarin.forms,Xamarin,Xamarin.forms,我们需要使用Xamarin.Forms在Android、iOS和Windows.UWP的3D地球地图上显示选定的城市。目前我们正在使用Xamarin.Forms.Maps,但它只显示地球的二维地图 我们如何制作地球的3D地图 注意:我们还需要地图的放大功能。如果您想要像Google Earth这样的东西,您可能需要创建自己的实现。但是,在Xamarin表单中,您可以使用现有的Xamarin.Forms.Maps控件并添加所谓的摄影机。基本上,这是一个你看地图的视角。这些可以在三维空间中,因此看起
注意:我们还需要地图的放大功能。如果您想要像Google Earth这样的东西,您可能需要创建自己的实现。但是,在Xamarin表单中,您可以使用现有的
Xamarin.Forms.Maps
控件并添加所谓的摄影机。基本上,这是一个你看地图的视角。这些可以在三维空间中,因此看起来您有一个三维地图。可以使用自定义渲染器创建此渲染器
在这些自定义渲染器中,您将遇到诸如俯仰、航向和距离之类的问题。此图显示了什么是什么:
iOS自定义渲染器
[assembly: ExportRenderer(typeof(Map3d), typeof(MapView3dRenderer))]
namespace MyApp.iOS.Renderers
{
public class MapView3dRenderer : MapRenderer
{
MKMapView _nativeMap;
protected override void OnElementChanged(ElementChangedEventArgs<View> e)
{
base.OnElementChanged(e);
if (e.NewElement != null && Control != null)
{
_nativeMap = Control as MKMapView;
}
}
protected override void OnElementPropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e)
{
base.OnElementPropertyChanged(sender, e);
if (_nativeMap == null)
return;
if (e.PropertyName == "VisibleRegion")
UpdateCameraView();
}
void UpdateCameraView()
{
var target = new CLLocationCoordinate2D(50.890119f, 5.857798f);
//Enable 3D buildings
_nativeMap.ShowsBuildings = true;
_nativeMap.PitchEnabled = true;
// Attach the camera
var camera = MKMapCamera.CameraLookingAtCenterCoordinate(target, 650, 60, 0);
_nativeMap.Camera = camera;
}
}
}
查看有关如何工作的详细信息。如果您想要像Google Earth这样的东西,您可能需要创建自己的实现。但是,在Xamarin表单中,您可以使用现有的
Xamarin.Forms.Maps
控件并添加所谓的摄影机。基本上,这是一个你看地图的视角。这些可以在三维空间中,因此看起来您有一个三维地图。可以使用自定义渲染器创建此渲染器
在这些自定义渲染器中,您将遇到诸如俯仰、航向和距离之类的问题。此图显示了什么是什么:
iOS自定义渲染器
[assembly: ExportRenderer(typeof(Map3d), typeof(MapView3dRenderer))]
namespace MyApp.iOS.Renderers
{
public class MapView3dRenderer : MapRenderer
{
MKMapView _nativeMap;
protected override void OnElementChanged(ElementChangedEventArgs<View> e)
{
base.OnElementChanged(e);
if (e.NewElement != null && Control != null)
{
_nativeMap = Control as MKMapView;
}
}
protected override void OnElementPropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e)
{
base.OnElementPropertyChanged(sender, e);
if (_nativeMap == null)
return;
if (e.PropertyName == "VisibleRegion")
UpdateCameraView();
}
void UpdateCameraView()
{
var target = new CLLocationCoordinate2D(50.890119f, 5.857798f);
//Enable 3D buildings
_nativeMap.ShowsBuildings = true;
_nativeMap.PitchEnabled = true;
// Attach the camera
var camera = MKMapCamera.CameraLookingAtCenterCoordinate(target, 650, 60, 0);
_nativeMap.Camera = camera;
}
}
}
查看有关如何工作的说明。感谢您的回答,但是我们需要在地球球形地图(地球)上显示某些城市的图钉。我们不需要放大到可以看到3D \倾斜街景的水平。感谢您的回答,但是我们需要在地球球形地图(地球)上显示某些城市的图钉。我们不需要放大到可以看到3D \倾斜街景的水平。