4

我正在尝试在 Android SDK 中设置自定义图像注释,但我无法做到。如果我使用代码创建带有默认图像的注释:

annotation.setAnnotationType(SKAnnotation.SK_ANNOTATION_TYPE_GREEN);

显示注释。但是当我用代码设置我的自定义图像时:

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

不显示注释。图像路径中的变量解析为(例如)"/data/data/com.kolobee.mini/files/stings_chueca.me9d_map.png":.

png这些图像是由应用程序通过使用代码从 a创建文件动态生成的Bitmap

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

为什么不显示注释?

4

1 回答 1

0

在 2.1.0 中,我们添加了对使用资源包中的图像的支持并扩展了完整路径图像的示例 - 这是更新后的 prepareAnnotations 代码:

 /**
 * 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's 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();
}
于 2014-07-29T09:07:45.123 回答