Search code examples
javaandroidskmaps

Occasionally see black rectangles overlaying SKMap when attempting to view map with SKAnnotations (purple pin marker type) on Android SDK 2.5


We're currently using Skobbler 2.5 to build an Android navigation app. One function within the app, allows you place annotations along a previously computed route. The annotations can be placed on the map while the SKMap is visible on screen or while it's in the background.

We have noticed that occasionally when adding annotations while the map is not currently visible and then going ahead and making the map visible results in black rectangles showing up in places where the annotations have been added.

The annotations themselves are added using the deprecated .setImagePath() method, but this is due to a workaround that was set up to make annotations visible when zooming out the map to a zoom level less than 4.

Here is an example of how annotations are currently added:

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

Yet for some reason occasionally the map will appear like this: enter image description here

Usually, it should look more like this:

enter image description here

Does anyone have any experience with this issue and know of a way to handle it correctly? Or perhaps there is some sort of race condition that I need to look out for?

Thanks for any help on the matter! Keith


Solution

  • I would have to look at all your project for a detailed answer. Absent that:

    • don't add annotations/visual elements when the map is not visible but set the changes in a "buffer" and perform the changes when the map is resumed
    • the imagePath API is deprecated, in the next update we'll remove it altogether. The custom views API offers more control and is more scalable, so we'll only support that API. You can try to switch all the annotations to use custom views and see if the problem still reproduces
    • are you using multiple map views in your app? if yes, please see: http://developer.skobbler.com/getting-started/android#sec033