为什么没有显示自定义注释?

时间:2014-06-25 11:56:49

标签: android skmaps

我尝试在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创建Bitmap文件:

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

为什么没有显示注释?

1 个答案:

答案 0 :(得分: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();
}