简体   繁体   中英

Here SDK mark position on map

I show the user's position on the map but what I want to do is mark the same

In onCreate I get the position of the user:

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

        // Get a MapView instance from layout


        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) {
            // TODO: Consider calling
            //    ActivityCompat#requestPermissions
            // here to request the missing permissions, and then overriding
            //   public void onRequestPermissionsResult(int requestCode, String[] permissions,
            //                                          int[] grantResults)
            // to handle the case where the user grants the permission. See the documentation
            // for ActivityCompat#requestPermissions for more details.
            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();
    }

Then what I want to do when the map is loaded is to show it and put a mark, I do it as follows:

 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());
                }
            }
        });
    }

But I get:

MapMarker(long, java.lang.Object)' has protected access in 'com.here.sdk.mapviewlite.MapMarker'

The problem is in this sentence:

                MapMarker mapMarker = new MapMarker( geoCoordinates, mapImage);

In the lite Product Variant we cannot pass the image Object directly to the MapMarker constructor.Below is the code snippet how we use image marker in lite Variant. The same is covered in the github example.

Github link: https://github.com/heremaps/here-sdk-examples/tree/master/examples/latest/lite/android/MapMarkerLite

  MapImage mapImage = MapImageFactory.fromResource(context.getResources(), R.drawable.here_car);

MapMarker mapMarker = new MapMarker(geoCoordinates);
mapMarker.addImage(mapImage, new MapMarkerImageStyle());

mapView.getMapScene().addMapMarker(mapMarker);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM