Marker anchor/offset on Mapbox 5.2

android anchor mapbox deprecated marker

248 观看


602 作者的声誉

I am setting markers on an Android Mapbox. Those markers are not squarred images and can not be centered, they need an offset.

On Google Maps I can use Anchor, X and Y.

On previous versions of Mapbox I could have used MarkerView with the same Anchor.

But now in Mapbox 5.2 MarkerView is deprecated.

So how to align my markers correctly on my map ?


作者: Ben-J 的来源 发布者: 2017 年 12 月 27 日

回应 (1)


602 作者的声誉

I am currently using this solution :

 * Generate a new bitmap to center it on Mapbox
 * @param icon the icon to display
 * @param centerFromTop The center of the picto from the top, in percentage, from 0.0 to 1.0. 1.0 
 *                      means the picto will be centered on the exact bottom of the original image.
 * @return
public static Bitmap cheatMapboxMarker(Bitmap icon, float centerFromTop) {
    int height = (int) (2 * centerFromTop * icon.getHeight());
    Bitmap loc_img = Bitmap.createBitmap(icon.getWidth(), height, Bitmap.Config.ARGB_8888);
    Canvas bitmapCanvas = new Canvas(loc_img);
    Bitmap tempBitmap = icon.copy(Bitmap.Config.ARGB_8888, false);
    bitmapCanvas.drawBitmap(tempBitmap, 0, 0, null);
    return loc_img;
作者: Ben-J 发布者: 25.04.2018 03:14