此处映射Android SDK位置指示器旋转

问题描述

我正在为我的应用程序使用HERE MAPS PREMIUM SDK。我需要随着方向的变化旋转当前位置图标。类似于其他地图中的当前位置指示器。由于HERE SDK没有默认方法,因此,每当调用onPositionUpdated()回调时,我都会使用以下代码来旋转位置指示器,

private PositioningManager.OnPositionChangedListener mapPositionHandler = new PositioningManager.OnPositionChangedListener() {
        @Override
        public void onPositionUpdated(PositioningManager.LocationMethod method,GeoPosition position,boolean isMapMatched) {                        
                        Matrix matrix = new Matrix();
                        matrix.postRotate((float) mHeading - mMap.getOrientation());
                        Bitmap newBitmap = Bitmap.createBitmap(myLocationIcon,myLocationIcon.getWidth(),myLocationIcon.getHeight(),matrix,true);
                        Image newImage = new Image();
                        newImage.setBitmap(newBitmap);
                        if (mMapFragment.getPositionIndicator() != null) {
                            mMapFragment.getPositionIndicator().setMarker(newImage);
                        }
}

此代码可以正常工作,但位置更新不顺利。每当位置更新时,都会有种反弹。关于此的任何建议将非常有帮助。

解决方法

您无需在每次“位置更新”中设置图标。只需通过调用setMarker方法将图像图标设置一次到位置指示器即可。 如果需要更改图标,则可以再次调用setMarker。 现在,由于需要随着方向的变化旋转位置图标,因此可以在onPositionUpdated内部使用以下代码块

<Button Name="load" Background="Pink" Content="Load File" Command="{Binding LoadFile}"/>

}

现在您也正在寻找PositionIndicator进行平滑更新。因此,您可以在设置标记时使用setSmoothPositionChange(true)方法,如下所示:

MainWindow

请注意:此方法setSmoothPositionChange(true)仅在最新的HERE MAP SDK(版本3.16)中可用,并且此版本的SDK使用Android X。

相关问答

错误1:Request method ‘DELETE‘ not supported 错误还原:...
错误1:启动docker镜像时报错:Error response from daemon:...
错误1:private field ‘xxx‘ is never assigned 按Alt...
报错如下,通过源不能下载,最后警告pip需升级版本 Requirem...