首页 > 解决方案 > 地图上的标记在这里 sdk android - 'com.here.sdk.mapviewlite.MapMarker' 中的受保护访问

问题描述

我收到此消息: MapMarker(long, java.lang.Object)' has protected access in 'com.here.sdk.mapviewlite.MapMarker'

在这一行:

MapMarker mapMarker = new MapMarker(geoCoordinates, mapImage);

我正在寻找的是添加当前位置的标记。因为你所在的地方在地图上显示但没有具体显示

public class MainActivity extends AppCompatActivity implements LocationListener {

    private static final String TAG = MainActivity.class.getSimpleName();
    private PermissionsRequestor permissionsRequestor;
    private MapViewLite mapView;
    private MapObjectsExample mapObjectsExample;

    protected LocationManager locationManager;

    double latitud, longitud;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
    

        locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
        if (ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
            return;
        }
        locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, this);

        Location location = locationManager.getLastKnownLocation(LocationManager.GPS_PROVIDER);
        latitud=location.getLatitude();
        longitud=location.getLongitude();

        mapView = findViewById(R.id.map_view);
        mapView.onCreate(savedInstanceState);

        handleAndroidPermissions();
    }

    private void handleAndroidPermissions() {
        permissionsRequestor = new PermissionsRequestor(this);
        permissionsRequestor.request(new PermissionsRequestor.ResultListener() {

            @Override
            public void permissionsGranted() {
                loadMapScene();
            }

            @Override
            public void permissionsDenied() {
                Log.e(TAG, "Permissions denied by user.");
            }
        });
    }

    @Override
    public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
        permissionsRequestor.onRequestPermissionsResult(requestCode, grantResults);
    }

 private void loadMapScene() {
        // Load a scene from the SDK to render the map with a map style.
        mapView.getMapScene().loadScene(MapStyle.NORMAL_DAY, new MapScene.LoadSceneCallback() {
            @Override
            public void onLoadScene(@Nullable MapScene.ErrorCode errorCode) {
                if (errorCode == null) {
                    mapObjectsExample = new MapObjectsExample(mapView);

                    GeoCoordinates geoCoordinates=new GeoCoordinates( latitud,longitud);
                    MapImage mapImage = MapImageFactory.fromResource(getApplicationContext().getResources(), R.drawable.here_car);
                    MapMarker mapMarker = new MapMarker(geoCoordinates, mapImage);

                    mapView.getMapScene().addMapMarker(mapMarker);

                    mapView.getCamera().setTarget(new GeoCoordinates( latitud,longitud));
                    mapView.getCamera().setZoomLevel(15);

                } else {
                    Log.d(TAG, "onLoadScene failed: " + errorCode.toString());
                }
            }
        });
    }

我该如何解决?

标签: androiddictionarysdk

解决方案


推荐阅读