Rakeshkumar Desai
How do you implement third dimension in maps?

Description: Suppose you need to go to a resturent which is at 10th floor in a building, how do you provide directions to user to that place?

By Rakeshkumar Desai in Xamarin on Apr 29 2021
  • Manikandan M
    Mar, 2022 3

    iOS
    [assembly: ExportRenderer(typeof(Map3d), typeof(MapView3dRenderer))]
    namespace MyApp.iOS.Renderers
    {
    public class MapView3dRenderer : MapRenderer
    {
    MKMapView _nativeMap;

    1. protected override void OnElementChanged(ElementChangedEventArgs<View> e)
    2. {
    3. base.OnElementChanged(e);
    4. if (e.NewElement != null && Control != null)
    5. {
    6. _nativeMap = Control as MKMapView;
    7. }
    8. }
    9. protected override void OnElementPropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e)
    10. {
    11. base.OnElementPropertyChanged(sender, e);
    12. if (_nativeMap == null)
    13. return;
    14. if (e.PropertyName == "VisibleRegion")
    15. UpdateCameraView();
    16. }
    17. void UpdateCameraView()
    18. {
    19. var target = new CLLocationCoordinate2D(50.890119f, 5.857798f);
    20. //Enable 3D buildings
    21. _nativeMap.ShowsBuildings = true;
    22. _nativeMap.PitchEnabled = true;
    23. // Attach the camera
    24. var camera = MKMapCamera.CameraLookingAtCenterCoordinate(target, 650, 60, 0);
    25. _nativeMap.Camera = camera;
    26. }
    27. }

    }

    Android
    // Create the camera
    CameraPosition cameraPosition = new CameraPosition.Builder()
    .Target(location)
    .Tilt(45)
    .Zoom(10)
    .Bearing(0)
    .Build();
    // Convert to an update object
    CameraUpdate cameraUpdate = CameraUpdateFactory.NewCameraPosition(cameraPosition);

    // Attach the camera
    map.MoveCamera(cameraUpdate); // map is of type GoogleMap

    • 0


Most Popular Job Functions


MOST LIKED QUESTIONS