2

我使用 Skobbler 地图。当我将自己的图标设置为注释时,不会调用 onAnnotationSelected。当我设置默认图标(annotation.setAnnotationType(SKAnnotation.SK_ANNOTATION_TYPE_PURPLE);)时,它工作正常。我做错了什么?

cursor = dataBaseHelper.getWritableDatabase().rawQuery(stringBuilder.toString(), null);
        int count = cursor.getCount();
        for (int i = 0; i < count; i++) {
            if (cursor.moveToPosition(i)) {
                SKAnnotation annotation = new SKAnnotation();
                annotation.setUniqueID(cursor.getInt(cursor.getColumnIndex(1)));
                annotation.setLocation(new SKCoordinate(cursor.getDouble(cursor.getColumnIndex(2)), cursor.getDouble(cursor.getColumnIndex(3))));
                annotation.setMininumZoomLevel(5);
                annotation.setImageSize(32);
                annotation.setImagePath(imagePath+cursor.getString(cursor.getColumnIndex(4)));
                mapView.addAnnotation(annotation, SKAnimationSettings.ANIMATION_NONE);
4

1 回答 1

2

您需要设置图像的中心点——点击注释将取决于该值。

// add an annotation with an image file 
    SKAnnotation annotation = new SKAnnotation(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);
于 2015-01-05T12:50:00.117 回答