I use Skobbler Maps.
When I set my own icons as annotations, onAnnotationSelected isn't called. And when I set default icons (annotation.setAnnotationType(SKAnnotation.SK_ANNOTATION_TYPE_PURPLE);
), It worked properly. What I'm doing wrong?
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);
You need to set the center point of the image- tapping on an annotation will depend on this value.
// 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);