Why aren't user annotations displayed?

I am trying to customize custom image annotations in the Android SDK and I cannot. If I create an annotation with a default image with code:

annotation.setAnnotationType(SKAnnotation.SK_ANNOTATION_TYPE_GREEN);

An annotation is displayed. But when I set my own image with code:

annotation.setImagePath(getActivity().getFilesDir() + "/" + data.getMapImagePath());
annotation.setImageSize(64);

Annotation is not displayed. Variables in the image path are enabled (for example): "/data/data/com.kolobee.mini/files/stings_chueca.me9d_map.png".

These images are generated dynamically by the application by creating a file pngfrom Bitmapwith the code:

FileOutputStream fos = context.openFileOutput(path, Context.MODE_PRIVATE);
bitmap.compress(CompressFormat.PNG, 75, fos);
fos.close();

Why are annotations not displayed?

+4
source share
1 answer

2.1.0 - readyAnnotations:

 /**
 * Draws annotations on map
 */
private void prepareAnnotations() {

    // get the annotation object
    SKAnnotation annotation1 = new SKAnnotation();
    // set unique id used for rendering the annotation
    annotation1.setUniqueID(10);
    // set annotation location
    annotation1.setLocation(new SKCoordinate(-122.4200, 37.7765));
    // set minimum zoom level at which the annotation should be visible
    annotation1.setMininumZoomLevel(5);
    // set the annotation type
    annotation1.setAnnotationType(SKAnnotation.SK_ANNOTATION_TYPE_RED);
    // render annotation on map
    mapView.addAnnotation(annotation1);

    SKAnnotation annotation2 = new SKAnnotation();
    annotation2.setUniqueID(11);
    annotation2.setLocation(new SKCoordinate(-122.410338, 37.769193));
    annotation2.setMininumZoomLevel(5);
    annotation2.setAnnotationType(SKAnnotation.SK_ANNOTATION_TYPE_GREEN);
    mapView.addAnnotation(annotation2);

    SKAnnotation annotation3 = new SKAnnotation();
    annotation3.setUniqueID(12);
    annotation3.setLocation(new SKCoordinate(-122.430337, 37.779776));
    annotation3.setMininumZoomLevel(5);
    annotation3.setAnnotationType(SKAnnotation.SK_ANNOTATION_TYPE_BLUE);
    mapView.addAnnotation(annotation3);

    // annotation drawn with drawable resource
    SKAnnotation annotation4 = new SKAnnotation();
    annotation4.setUniqueID(13);
    annotation4.setLocation(new SKCoordinate(-122.425, 37.774));
    annotation4.setMininumZoomLevel(5);
    SKAnnotationView annotationView = new SKAnnotationView();
    // set the drawable resource to be rendered as annotation
    annotationView.setDrawableResourceId(R.drawable.dot_full);
    // set the size of the annotation (this value must be a power of 2)
    annotationView.setProperSize(16);
    annotation4.setAnnotationView(annotationView);
    mapView.addAnnotation(annotation4);

    // annotation drawn with image from a local file
    SKAnnotation annotation5 = new SKAnnotation();
    annotation5.setUniqueID(14);
    annotation5.setLocation(new SKCoordinate(-122.417, 37.772));
    annotation5.setMininumZoomLevel(5);

    // set path to an image whose dimensions are powers of 2
    // image is selected according to screen density
    DisplayMetrics metrics = new DisplayMetrics();
    getWindowManager().getDefaultDisplay().getMetrics(metrics);
    if (metrics.densityDpi < DisplayMetrics.DENSITY_HIGH) {
        annotation5.setImagePath(app.getMapResourcesDirPath() + "images/dot_blue_medium.png");
    } else {
        annotation5.setImagePath(app.getMapResourcesDirPath() + "images/dot_blue_high.png");
    }
    annotation5.setImageSize(40);
    mapView.addAnnotation(annotation5);

    selectedAnnotation = annotation1;
    // set map zoom level
    mapView.setZoom(14);
    // center map on a position
    mapView.centerMapOnPosition(new SKCoordinate(-122.4200, 37.7765));
    updatePopupPosition();
}
0

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


All Articles