Android 如何在地图上的注释中设置自定义图像?

Android 如何在地图上的注释中设置自定义图像?,android,image,annotations,skmaps,Android,Image,Annotations,Skmaps,如标题所示,我尝试将自己的图像放在地图上的注释中。 为此,我使用以下代码: annotation.setImagePath (mImagePath); annotation.setImageSize (4096); annotation.setOffset (mSKScreenPoint)); 没有错误,但没有显示任何内容 但我遵循了医生的指示: "Sets the absolute path of the image file to be added as an annotation. T

如标题所示,我尝试将自己的图像放在地图上的注释中。 为此,我使用以下代码:

annotation.setImagePath (mImagePath);
annotation.setImageSize (4096);
annotation.setOffset (mSKScreenPoint));
没有错误,但没有显示任何内容

但我遵循了医生的指示:

"Sets the absolute path of the image file to be added as an annotation. 
The picture must be a square image and the size must be a power of 2. 
_ (32x32, 64x64, etc.)."
我的图像大小是64*64

多亏了这篇文章,我有了第一个迹象,但什么也没有出现:


所以我把我的图像转换成png-24,但仍然没有结果。((

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

更新:添加了2.2.0 customView支持:

/**
 * 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, SKAnimationSettings.ANIMATION_NONE);

    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, SKAnimationSettings.ANIMATION_NONE);

    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, SKAnimationSettings.ANIMATION_NONE);

    // add an annotation with an image file
    SKAnnotation annotation = new SKAnnotation();
    annotation.setUniqueID(13);
    annotation.setLocation(new SKCoordinate(-122.434516, 37.770712));
    annotation.setMininumZoomLevel(5);


    DisplayMetrics metrics = new DisplayMetrics();
    getWindowManager().getDefaultDisplay().getMetrics(metrics);
    if (metrics.densityDpi < DisplayMetrics.DENSITY_HIGH) {
        // set the center point of the image - tapping on an annotation will
        // depend on
        // this value . Also the actual gps coordinates of the annotation
        // will
        // be in the center of the image.
        annotation.getOffset().setX(16);
        annotation.getOffset().setY(16);
        annotation.setImagePath(SKMaps.getInstance().getMapInitSettings().getMapResourcesPath()
                + "/.Common/poi_marker.png");
        // set the size of the image in pixels
        annotation.setImageSize(32);
    } else {
        // set the center point of the image - tapping on an annotation will
        // depend on
        // this value . Also the actual gps coordinates of the annotation
        // will
        // be in the center of the image.
        annotation.getOffset().setX(32);
        annotation.getOffset().setY(32);
        annotation.setImagePath(SKMaps.getInstance().getMapInitSettings().getMapResourcesPath()
                + "/.Common/poi_marker_retina.png");
        // set the size of the image in pixels
        annotation.setImageSize(64);

    }
    mapView.addAnnotation(annotation, SKAnimationSettings.ANIMATION_NONE);


    // add an annotation with a drawable resource
    SKAnnotation annotationDrawable = new SKAnnotation();
    annotationDrawable.setUniqueID(14);
    annotationDrawable.setLocation(new SKCoordinate(-122.437182, 37.777079));
    annotationDrawable.setMininumZoomLevel(5);
    // set the center point of the image - tapping on an annotation will
    // depend on
    // this value . Also the actual gps coordinates of the annotation will
    // be in the center of the image.
    annotationDrawable.setOffset(new SKScreenPoint(64, 64));
    SKAnnotationView annotationView = new SKAnnotationView();
    annotationView.setDrawableResourceId(R.drawable.icon_map_popup_navigate);
    // set the width and height of the image in pixels (they have to be
    // powers of 2)
    annotationView.setWidth(128);
    annotationView.setHeight(128);
    annotationDrawable.setAnnotationView(annotationView);
    mapView.addAnnotation(annotationDrawable, SKAnimationSettings.ANIMATION_NONE);


    // // add an annotation with a view
    SKAnnotation annotationFromView = new SKAnnotation();
    annotationFromView.setUniqueID(15);
    annotationFromView.setLocation(new SKCoordinate(-122.423573, 37.761349));
    annotationFromView.setMininumZoomLevel(5);
    annotationView = new SKAnnotationView();

    // set view object to be displayed as annotation
    annotationView.setView(customView);
    annotationFromView.setAnnotationView(annotationView);
    mapView.addAnnotation(annotationFromView, SKAnimationSettings.ANIMATION_NONE);


    selectedAnnotation = annotation1;
    // set map zoom level
    mapView.setZoom(13);
    // center map on a position
    mapView.centerMapOnPosition(new SKCoordinate(-122.4200, 37.7765));
}
/**
*在地图上绘制注释
*/
专用无效准备注释(){
//获取注释对象
SKAnnotation annotation1=新SKAnnotation();
//设置用于呈现注释的唯一id
注释1.setUniqueID(10);
//设置注释位置
注释1.设置位置(新SK坐标(-122.4200,37.7765));
//设置注释应可见的最小缩放级别
注释1.setMininumZoomLevel(5);
//设置注释的类型
annotation1.setAnnotationType(SKAnnotation.SK_ANNOTATION_TYPE_RED);
//在地图上渲染注释
mapView.addAnnotation(注释1,SKAnimationSettings.ANIMATION\u无);
SKAnnotation annotation2=新的SKAnnotation();
注释2.setUniqueID(11);
注释2.设置位置(新SK坐标(-122.410338,37.769193));
注释2.setMininumZoomLevel(5);
annotation2.setAnnotationType(SKAnnotation.SK_ANNOTATION_TYPE_GREEN);
mapView.addAnnotation(annotation2,SKAnimationSettings.ANIMATION\u无);
SKAnnotation annotation3=新SKAnnotation();
注释3.setUniqueID(12);
注释3.设置位置(新SK坐标(-122.430337,37.779776));
注释3.setMininumZoomLevel(5);
annotation3.setAnnotationType(SKAnnotation.SK_ANNOTATION_TYPE_BLUE);
mapView.addAnnotation(annotation3,SKAnimationSettings.ANIMATION\u无);
//使用图像文件添加注释
SKAnnotation=新SKAnnotation();
注:setUniqueID(13);
注释.设置位置(新SK坐标(-122.434516,37.770712));
注释.setMininumZoomLevel(5);
DisplayMetrics=新的DisplayMetrics();
getWindowManager().getDefaultDisplay().getMetrics(度量);
if(metrics.densityDpi
如果图像是64*64,则应将图像大小设置为64

annotation.setImageSize(64);

mImagePath应该是图像文件的绝对路径-正确吗?请发送电子邮件至dev@skobbler.com并附加您正试图使用的图标&mImagePath和mskscreenpoint的当前值以及
64px
图像,您应该将图像大小设置为
64
而不是
4096
。自定义图像我这边也不行。这是我正在使用的图像:(Photoshop生成,64x64,24位透明PNG)SKAnnotation*annotation=[SKAnnotation];//设置唯一ID//设置位置annotation.imagePath=[[NSBundle]