Search code examples
androidskmaps

Skobbler Annotation disappears from map when zooming out on Android


Currently, I am adding a list of annotations to a mapview with code similar to the following:

// Add to map view
SKAnnotation annotation = new SKAnnotation(i++);
annotation.getLocation().setLongitude(result.longitude);
annotation.getLocation().setLatitude(result.latitude);
annotation.setMininumZoomLevel(1);
annotation.setAnnotationType(SKAnnotation.SK_ANNOTATION_TYPE_PURPLE);
mapView.addAnnotation(annotation, SKAnimationSettings.ANIMATION_POP_OUT);

Yet whenever I view the annotations on the map, they disappear after I zoom out to anything under zoom level 4.0. Looking at the docs for the Annotation class (as well as confirming in the code), I see that the default zoom level is set to 4, yet it seems that my call to .setMinimumZoomLevel is ignored.

Does anyone have any insight into what is happening or if this might be a known bug within the SDK?

I'm using Skobbler 2.5 on Android.

Thanks for any help in the matter!


Solution

  • Based off Ando's comment on the original question and referencing the documentation here, I updated the code to use the workaround he described to allow annotations to show up down to zoom level 2.

    Original code:

    SKAnnotation annotation = new SKAnnotation(i++);
    annotation.getLocation().setLongitude(result.longitude);
    annotation.getLocation().setLatitude(result.latitude);
    annotation.setMininumZoomLevel(1); // Note: this does not work
    annotation.setAnnotationType(SKAnnotation.SK_ANNOTATION_TYPE_PURPLE);
    mapView.addAnnotation(annotation, SKAnimationSettings.ANIMATION_POP_OUT);
    

    Updated code:

    SKAnnotation annotation = new SKAnnotation(i++);
    annotation.getLocation().setLongitude(result.longitude);
    annotation.getLocation().setLatitude(result.latitude);
    annotation.setMininumZoomLevel(2);
    DisplayMetrics metrics = new DisplayMetrics();
    getWindowManager().getDefaultDisplay().getMetrics(metrics);
    if (metrics.densityDpi < DisplayMetrics.DENSITY_HIGH) {
        annotation.setImagePath(SKMaps.getInstance().getMapInitSettings().
                getMapResourcesPath() + "/.Common/[email protected]");
        // set the size of the image in pixel
        annotation.setImageSize(128);
    } else {
        annotation.setImagePath(SKMaps.getInstance().getMapInitSettings().
                getMapResourcesPath()+ "/.Common/[email protected]");
        // set the size of the image in pixels
        annotation.setImageSize(256);
    }
    mapView.addAnnotation(annotation, SKAnimationSettings.ANIMATION_POP_OUT);
    

    A couple things to note:

    1. .setImagePath() and .setImageSize() are both deprecated methods in the latest SDK even though they're still referenced in the documentation above. Not sure if that means there is another alternative to displaying images via an absolute path approach, or if they're simply phasing this functionality out.
    2. In my particular example, we're using the purple pin to display annotations, but the absolute path file name for that pin is actually called icon_greypin. It looks like the other pin image file name are named appropriately however.

    Anyways, this served as a solution for my particular problem until the SDK is updated, so I'm marking it as the answer and I hope it helps someone else! Thanks to Ando for the step in the right direction!