📜 ⬆️ ⬇️

Yandex Map Kit for Android. Card rotation

Hello!
In this message I will describe the inclusion of the map rotation function in the application using the Yandex Map Kit for Android . A message was written based on Issue # 99 , which remained unresolved.



A small retreat. It was not possible to start working with the map according to the description in the Wiki section “How to start work” . The application crashed when starting with the error "Caused by: android.view.InflateException: Binary XML file line # 7: Error inflating class ru.yandex.yandexmapkit.MapView". It helped connect to the classes.jar project, located in yandexmapkit-library \ libs.

Like the author of Issue # 99, the MapController method setRotateAnimtionTo rotated the map, but instead of the map tiles, it received tiles with the words "There is no data for this site."
')
Using the hint support
By rotation, it was done for my location and, as it were, represents internal functionality.
The problem you have in turning is that the center point of rotation is not set. But all these APIs are alas closed for now.

investigated the class MyLocationOverlay (bytecode can be viewed in Eclipse), the following lines were found
223 aload_0 [this] 224 invokevirtual ru.yandex.yandexmapkit.overlay.location.MyLocationOverlay.f() : boolean [168] 227 ifeq 258 230 aload_0 [this] 231 getfield ru.yandex.yandexmapkit.overlay.location.MyLocationOverlay.y : al [78] 234 aload_0 [this] 235 invokevirtual ru.yandex.yandexmapkit.overlay.location.MyLocationOverlay.getMyLocationItem() : ru.yandex.yandexmapkit.overlay.location.MyLocationItem [171] 238 invokevirtual ru.yandex.yandexmapkit.overlay.location.MyLocationItem.getBearing() : float [154] 241 invokevirtual al.a(float) : void [79] 244 aload_0 [this] 245 getfield ru.yandex.yandexmapkit.overlay.location.MyLocationOverlay.y : al [78] 248 aload_0 [this] 249 invokevirtual ru.yandex.yandexmapkit.overlay.location.MyLocationOverlay.getMyLocationItem() : ru.yandex.yandexmapkit.overlay.location.MyLocationItem [171] 252 invokevirtual ru.yandex.yandexmapkit.overlay.location.MyLocationItem.getPoint() : cp [156] 255 invokevirtual al.a(cp) : void [80] 258 aload_0 [this] 259 invokevirtual ru.yandex.yandexmapkit.overlay.location.MyLocationOverlay.getMapController() : ru.yandex.yandexmapkit.MapController [170] 262 invokevirtual ru.yandex.yandexmapkit.MapController.notifyRepaint() : void [140] 

where al is what the MapController getMapRotator () method returns. MyLocationItem is an OverlayItem extension, whose getPoint () method is inherited in MyLocationItem (will be required to get an unavailable instance of the cp class). Having seen all this, it is easy to guess that the method of the class al a (cp point) sets the coordinates of the axis around which the map rotates, and al.a (float bearing) the angle of rotation. The class al (recall that the instance obtained by the getMapRotator () method of the MapController class) has another method a (boolean enableRotation) for which there was a hunch that it allows the map to rotate, which was later confirmed.

Now everything is ready to rotate the map, for example, when changing the azimuth. How to get the values ​​of the azimuth when changing the position of the device in space is well described in the book . It remains only to insert the following code into the event handler for the change in azimuth.
  GeoPoint geoPoint = mMapController.getMapCenter(); //     OverlayItem overlayItem = new OverlayItem(geoPoint, null); //       cp,       mMapController.getMapRotator().a(bearing); //   mMapController.getMapRotator().a(overlayItem.getPoint()); //      

Where
  MapController mMapController; MapView mMapView; mMapView = (MapView) findViewById(R.id.map); mMapController = mMapView.getMapController(); mMapController.getMapRotator().a(true); //   

Result

Source: https://habr.com/ru/post/167807/


All Articles