heremaps / here-android-sdk-examples

Java-based projects using the HERE SDK for Android.
Apache License 2.0
145 stars 191 forks source link

Position indicator marker icon orientation issue #338

Open binod-techindustan opened 4 years ago

binod-techindustan commented 4 years ago

The icon rotate properly during navigation but when we zoom-in or zoom-out the map then position indicator icon is not rotating properly. @starand Please check it.

Merlin1stHere commented 4 years ago

@binod-techindustan The built-in PositionIndicator does not support rotation. Please specify what do you mean?

binod-techindustan commented 4 years ago

@Merlin1stHere we are setting icon using the below code.

Bitmap truckBitmap = BitmapFactory.decodeResource(getResources(),
                                R.drawable.truck);
Image image = new Image();
image.setBitmap(truckBitmap);
mMapFragment.getPositionIndicator().setMarker(image);

Basically the issue is when we zoom in or out the map we set the map update mode to NONE.

NavigationManager.getInstance().setMapUpdateMode(NavigationManager.MapUpdateMode.NONE);

So after that, the map orientation stops but the position indicator icon keeps moving toward a destination but the icon orientation doesn't change. As our icon shape is rectangular in shape it doesn't look good.

Merlin1stHere commented 4 years ago

@binod-techindustan The build-in PositionIndicator doesn't support rotation. You can rotate the image for the marker using the current map orientation in callback onMapTransformEnd.

binod-techindustan commented 4 years ago

@Merlin1stHere can we update the icon size according to the zoom level?

Merlin1stHere commented 4 years ago

@binod-techindustan By the same way. Set a new image for PositionIndicator.

binod-techindustan commented 4 years ago

@Merlin1stHere yes I tried setting the orientation. But it misbehaves

    m_map.addTransformListener(new Map.OnTransformListener() {
                            @Override
                            public void onMapTransformStart() {

                            }
                            @Override
                            public void onMapTransformEnd(MapState mapState) {
                                Bitmap bitmap=Utilities.Companion.rotateBitmap(truckBitmap,mapState.getOrientation());
                                image.setBitmap(bitmap);
                                m_mapFragment.getPositionIndicator().setMarker(image);
                            }
                        });
Merlin1stHere commented 4 years ago

@binod-techindustan What units does the function Utilities.Companion.rotateBitmap accept for the second parameter? Radian or Degrees? MapState.getOrientation returns degrees.

binod-techindustan commented 4 years ago

@Merlin1stHere it's in degrees

  fun rotateBitmap(source: Bitmap, angle: Float): Bitmap {
            val matrix = Matrix()
            matrix.postRotate(angle)
            return Bitmap.createBitmap(source, 0, 0, source.width, source.height, matrix, true)
        }
Merlin1stHere commented 4 years ago

@binod-techindustan 1) It is better to use OnMapRenderListener callback from MapFragment (or MapView). 2) Use -Map.getOrientarion() for angle.

@Override
public void onPreDraw() {
    Matrix matrix = new Matrix();
    matrix.postRotate(-m_map.getOrientation());
    Bitmap newBitmap = Bitmap.createBitmap(m_markerBitmap, 0, 0, m_markerBitmap.getWidth(), m_markerBitmap.getHeight(), matrix, true);
    Image newImage = new Image();
    newImage.setBitmap(newBitmap);
    m_mapFragment.getPositionIndicator().setMarker(newImage);
}
binod-techindustan commented 4 years ago

truck This is the icon we are using please check the shape. Its orientation is not working properly even after this implementation.

binod-techindustan commented 4 years ago

@Merlin1stHere Please check the icon

Merlin1stHere commented 4 years ago

@binod-techindustan Please double check your implementation. It can't depend on image.

binod-techindustan commented 4 years ago

@Merlin1stHere at the beginning itself, the icon rotates 45 degree. Here is the implementation

m_mapFragment.addOnMapRenderListener(new OnMapRenderListener() {
            @Override
            public void onPreDraw() {
                Matrix matrix = new Matrix();
                matrix.postRotate(-m_map.getOrientation());
                Bitmap newBitmap = Bitmap.createBitmap(truckBitmap, 0, 0, truckBitmap.getWidth(), truckBitmap.getHeight(), matrix, true);
                Image newImage = new Image();
                newImage.setBitmap(newBitmap);
                m_mapFragment.getPositionIndicator().setMarker(newImage);
            }

            @Override
            public void onPostDraw(boolean b, long l) {

            }

            @Override
            public void onSizeChanged(int i, int i1) {

            }

            @Override
            public void onGraphicsDetached() {

            }

            @Override
            public void onRenderBufferCreated() {

            }
        });
binod-techindustan commented 4 years ago

Screenshot_2020-03-05-14-29-06-79_72fda9f17b112338a9969b167fcb3fa2 @Merlin1stHere please check the screenshot

Merlin1stHere commented 4 years ago

@binod-techindustan My code just rotates the bitmap with the map. To align image with road you should take to account heading fo the current GeoPosition. (GeoPosition.getHeading()).

Merlin1stHere commented 4 years ago

@binod-techindustan Map.getOrientation returns orientation in degrees relative to north.

binod-techindustan commented 4 years ago

@Merlin1stHere GeoPosition.getHeading() returns a double value which is the current course heading. How can we relate this value to the positioning icon?

Merlin1stHere commented 4 years ago

@binod-techindustan Bitmaps are always drawn relative to the screen. It does not depend on the orientation of the map. So we can rotate a bitmap using map.getOrientation to sync bitmap orientation with the map. But if you need to rotate the bitmap using the current heading (to align the bitmap with the road), you must take this angle into account during rotation. I believe the code below will work fine: matrix.postRotate(currentCourse-m_map.getOrientation())

binod-techindustan commented 4 years ago

Thanks @Merlin1stHere it's working fine now.

binod-techindustan commented 4 years ago

@Merlin1stHere here is another issue after changing this. I show the position doesn't smoothly changed the position it's like jumping for every position update. It is mostly visible when we zoom in.

binod-techindustan commented 4 years ago

@Merlin1stHere re drawing position indication on this listener causing crash during navigation, in some device.

m_mapFragment.addOnMapRenderListener(new OnMapRenderListener() {
            @Override
            public void onPreDraw() {
                Matrix matrix = new Matrix();
                matrix.postRotate(-m_map.getOrientation());
                Bitmap newBitmap = Bitmap.createBitmap(truckBitmap, 0, 0, truckBitmap.getWidth(), truckBitmap.getHeight(), matrix, true);
                Image newImage = new Image();
                newImage.setBitmap(newBitmap);
                m_mapFragment.getPositionIndicator().setMarker(newImage);
            }

            @Override
            public void onPostDraw(boolean b, long l) {

            }

            @Override
            public void onSizeChanged(int i, int i1) {

            }

            @Override
            public void onGraphicsDetached() {

            }

            @Override
            public void onRenderBufferCreated() {

            }
        });
Merlin1stHere commented 4 years ago

@binod-techindustan Do you have a stack trace?

binod-techindustan commented 4 years ago

@Merlin1stHere here is backtrace from Playstore crash report:

backtrace:
  #00  pc 000000000006f80c  /apex/com.android.runtime/lib64/bionic/libc.so (memset+140)
  #01  pc 000000000039f684  /vendor/lib64/egl/libGLESv2_adreno.so
  #02  pc 00000000001db740  /vendor/lib64/egl/libGLESv2_adreno.so
  #03  pc 00000000001de950  /vendor/lib64/egl/libGLESv2_adreno.so
  #04  pc 000000000014163c  /vendor/lib64/egl/libGLESv2_adreno.so
  #05  pc 000000000013e044  /vendor/lib64/egl/libGLESv2_adreno.so
  #06  pc 0000000000158ea8  /vendor/lib64/egl/libGLESv2_adreno.so
  #07  pc 0000000000171324  /vendor/lib64/egl/libGLESv2_adreno.so
  #08  pc 00000000000e4980  /vendor/lib64/egl/libGLESv2_adreno.so (glTexImage2D+144)
  #09  pc 0000000000992714  /data/app/com.example-cGvwQk3cG1IhqfrsyWkwRA==/lib/arm64/libMAPSJNI.so
  #10  pc 000000000072c830  /data/app/com.example-cGvwQk3cG1IhqfrsyWkwRA==/lib/arm64/libMAPSJNI.so
  #11  pc 00000000004dab20  /data/app/com.example-cGvwQk3cG1IhqfrsyWkwRA==/lib/arm64/libMAPSJNI.so
  #12  pc 0000000000509b0c  /data/app/com.example-cGvwQk3cG1IhqfrsyWkwRA==/lib/arm64/libMAPSJNI.so
  #13  pc 000000000050a588  /data/app/com.example-cGvwQk3cG1IhqfrsyWkwRA==/lib/arm64/libMAPSJNI.so
  #14  pc 000000000053be78  /data/app/com.example-cGvwQk3cG1IhqfrsyWkwRA==/lib/arm64/libMAPSJNI.so
  #15  pc 00000000004fcf28  /data/app/com.example-cGvwQk3cG1IhqfrsyWkwRA==/lib/arm64/libMAPSJNI.so
  #16  pc 00000000005cece0  /data/app/com.example-cGvwQk3cG1IhqfrsyWkwRA==/lib/arm64/libMAPSJNI.so
  #17  pc 000000000053be78  /data/app/com.example-cGvwQk3cG1IhqfrsyWkwRA==/lib/arm64/libMAPSJNI.so
  #18  pc 00000000004fcf28  /data/app/com.example-cGvwQk3cG1IhqfrsyWkwRA==/lib/arm64/libMAPSJNI.so
  #19  pc 00000000005cece0  /data/app/com.example-cGvwQk3cG1IhqfrsyWkwRA==/lib/arm64/libMAPSJNI.so
  #20  pc 000000000053be78  /data/app/com.example-cGvwQk3cG1IhqfrsyWkwRA==/lib/arm64/libMAPSJNI.so
  #21  pc 000000000076cce0  /data/app/com.example-cGvwQk3cG1IhqfrsyWkwRA==/lib/arm64/libMAPSJNI.so
  #22  pc 000000000076c930  /data/app/com.example-cGvwQk3cG1IhqfrsyWkwRA==/lib/arm64/libMAPSJNI.so
  #23  pc 00000000006d3c50  /data/app/com.example-cGvwQk3cG1IhqfrsyWkwRA==/lib/arm64/libMAPSJNI.so
  #24  pc 00000000006d3974  /data/app/com.example-cGvwQk3cG1IhqfrsyWkwRA==/lib/arm64/libMAPSJNI.so
  #25  pc 00000000006d8e20  /data/app/com.example-cGvwQk3cG1IhqfrsyWkwRA==/lib/arm64/libMAPSJNI.so
  #26  pc 000000000050f3e8  /data/app/com.example-cGvwQk3cG1IhqfrsyWkwRA==/lib/arm64/libMAPSJNI.so
  #27  pc 000000000050ef4c  /data/app/com.example-cGvwQk3cG1IhqfrsyWkwRA==/lib/arm64/libMAPSJNI.so
  #28  pc 00000000004f170c  /data/app/com.example-cGvwQk3cG1IhqfrsyWkwRA==/lib/arm64/libMAPSJNI.so
  #29  pc 000000000032b83c  /data/app/com.example-cGvwQk3cG1IhqfrsyWkwRA==/lib/arm64/libMAPSJNI.so
  #30  pc 000000000034afe8  /data/app/com.example-cGvwQk3cG1IhqfrsyWkwRA==/lib/arm64/libMAPSJNI.so
  #31  pc 000000000029eaf0  /data/app/com.example-cGvwQk3cG1IhqfrsyWkwRA==/lib/arm64/libMAPSJNI.so
  #32  pc 000000000016f7d8  /data/app/com.example-cGvwQk3cG1IhqfrsyWkwRA==/oat/arm64/base.odex (art_jni_trampoline+152)
  #33  pc 00000000001f8640  /data/app/com.example-cGvwQk3cG1IhqfrsyWkwRA==/oat/arm64/base.odex (com.nokia.maps.k2.onDrawFrame+496)
  #34  pc 0000000000443418  /data/app/com.example-cGvwQk3cG1IhqfrsyWkwRA==/oat/arm64/base.odex (com.nokia.maps.e0$d.run+3160)
  #35  pc 0000000000137334  /apex/com.android.runtime/lib64/libart.so (art_quick_invoke_stub+548)
  #36  pc 0000000000145fec  /apex/com.android.runtime/lib64/libart.so (art::ArtMethod::Invoke(art::Thread*, unsigned int*, unsigned int, art::JValue*, char const*)+244)
  #37  pc 00000000004b2d0c  /apex/com.android.runtime/lib64/libart.so (art::(anonymous namespace)::InvokeWithArgArray(art::ScopedObjectAccessAlreadyRunnable const&, art::ArtMethod*, art::(anonymous namespace)::ArgArray*, art::JValue*, char const*)+104)
  #38  pc 00000000004b3e20  /apex/com.android.runtime/lib64/libart.so (art::InvokeVirtualOrInterfaceWithJValues(art::ScopedObjectAccessAlreadyRunnable const&, _jobject*, _jmethodID*, jvalue const*)+416)
  #39  pc 00000000004f47e8  /apex/com.android.runtime/lib64/libart.so (art::Thread::CreateCallback(void*)+1176)
  #40  pc 00000000000d6b70  /apex/com.android.runtime/lib64/bionic/libc.so (__pthread_start(void*)+36)
  #41  pc 0000000000074eac  /apex/com.android.runtime/lib64/bionic/libc.so (__start_thread+64)
prasannab069 commented 4 years ago

Hi i am also implementing as you mentioned above. It would be helpful if you let me know the fix for the crash mentioned above.