如何显示黑莓MapField可不止一个位置?(How to show more than one l

2019-07-22 06:25发布

我能够使用共同坐标或经度和纬度,显示出一个位置,但我不知道如何显示在BlackBerry MapField.If多个位置是我可以请占有率如何做到这一点..

Answer 1:

相同的方式, 如何展现我们自己的黑莓地图图标? 。

通过坐标的阵列到定制MapField可,定义位置点的位图和油漆它为每个坐标在定制MapField可paint()方法。

请记住,放大/缩小CustomMapField所有位置点的最佳匹配。

实施样本

让我们显示利物浦谢菲尔德和伦敦自定义位图的图标(黄圈黑边)。 代码定制MapField可:

class MultyMapField extends MapField {
    Coordinates[] mPoints = new Coordinates[0];
    Bitmap mPoint;
    Bitmap mPointsBitmap;
    XYRect mDest;
    XYRect[] mPointDest;

    public void addCoordinates(Coordinates coordinates) {
        Arrays.add(mPoints, coordinates);
        zoomToFitPoints();
        repaintPoints();
    }

    protected void zoomToFitPoints() {
        // zoom to max
        setZoom(getMaxZoom());

        // get pixels of all points
        int minLeft = getWidth();
        int minUp = getHeight();
        int maxRight = 0;
        int maxDown = 0;
        Coordinates minLeftCoordinates = null;
        Coordinates minUpCoordinates = null;
        Coordinates maxRightCoordinates = null;
        Coordinates maxDownCoordinates = null;
        for (int i = 0; i < mPoints.length; i++) {
            XYPoint point = new XYPoint();
            convertWorldToField(mPoints[i], point);
            if (point.x <= minLeft) {
                minLeft = point.x;
                minLeftCoordinates = mPoints[i];
            }
            if (point.x >= maxRight) {
                maxRight = point.x;
                maxRightCoordinates = mPoints[i];
            }
            if (point.y <= minUp) {
                minUp = point.y;
                minUpCoordinates = mPoints[i];
            }
            if (point.y >= maxDown) {
                maxDown = point.y;
                maxDownCoordinates = mPoints[i];
            }
        }

        double moveToLat = maxDownCoordinates.getLatitude()
                + (minUpCoordinates.getLatitude() - maxDownCoordinates
                        .getLatitude()) / 2;
        double moveToLong = minLeftCoordinates.getLongitude()
                + (maxRightCoordinates.getLongitude() - minLeftCoordinates
                        .getLongitude()) / 2;
        Coordinates moveTo = new Coordinates(moveToLat, moveToLong, 0);
        moveTo(moveTo);
        // zoom to min left up, max right down pixels + 1
        int zoom = getZoom();
        boolean outOfBounds = false;
        while (!outOfBounds && zoom > getMinZoom()) {
            zoom--;
            setZoom(zoom);
            XYPoint point = new XYPoint();
            try {
                convertWorldToField(minLeftCoordinates, point);
                if (point.x < 0)
                    outOfBounds = true;
                convertWorldToField(minUpCoordinates, point);
                if (point.y < 0)
                    outOfBounds = true;
                convertWorldToField(maxRightCoordinates, point);
                if (point.x > getWidth())
                    outOfBounds = true;
                convertWorldToField(maxDownCoordinates, point);
                if (point.y > getHeight())
                    outOfBounds = true;
            } catch (IllegalArgumentException ex) {
                outOfBounds = true;
            }
        }
        zoom++;
        setZoom(zoom);
    }

    protected void repaintPoints() {
        mPointsBitmap = new Bitmap(getWidth(), getHeight());
        mPointsBitmap.createAlpha(Bitmap.ALPHA_BITDEPTH_8BPP);
        mDest = new XYRect(0, 0, mPointsBitmap.getWidth(), mPointsBitmap
                .getHeight());
        Graphics g = new Graphics(mPointsBitmap);
        if (null != mPoint) {
            mPointDest = new XYRect[mPoints.length];
            for (int i = 0; i < mPoints.length; i++) {
                if (null == mPointDest[i]) {
                    XYPoint fieldOut = new XYPoint();
                    convertWorldToField(mPoints[i], fieldOut);
                    int imgW = mPoint.getWidth();
                    int imgH = mPoint.getHeight();
                    mPointDest[i] = new XYRect(fieldOut.x - imgW / 2,
                            fieldOut.y - imgH, imgW, imgH);
                }
                g.drawBitmap(mPointDest[i], mPoint, 0, 0);
            }
        }
    }

    protected void paint(Graphics graphics) {
        super.paint(graphics);
        if (null != mPointsBitmap) {
            graphics.setGlobalAlpha(100);
            graphics.drawBitmap(mDest, mPointsBitmap, 0, 0);
        }
    }
}

使用的示例:

class Scr extends MainScreen {
    // test coordinates:
    // London
    // 51.507778, -0.128056
    Coordinates mLondonC = new Coordinates(51.507778, -0.128056, 0);
    // Liverpool
    // 53.4, -2.983333
    Coordinates mLiverpoolC = new Coordinates(53.4, -2.983333, 0);
    // Sheffield
    // 53.385833, -1.469444
    Coordinates mSheffieldC = new Coordinates(53.385833, -1.469444, 0);

    MultyMapField mMultyMapField;

    public Scr() {
        add(mMultyMapField = new MultyMapField());
        mMultyMapField.mPoint = createPointBitmap();
    }

    protected void onUiEngineAttached(boolean attached) {
        super.onUiEngineAttached(attached);
        if (attached) {
            mMultyMapField.addCoordinates(mLondonC);
            mMultyMapField.addCoordinates(mLiverpoolC);
            mMultyMapField.addCoordinates(mSheffieldC);
        }
    }

    private Bitmap createPointBitmap() {
        int r = 10;
        Bitmap result = new Bitmap(2 * r, 2 * r);
        result.createAlpha(Bitmap.ALPHA_BITDEPTH_8BPP);
        Graphics g = new Graphics(result);
        g.setColor(Color.BLACK);
        g.fillEllipse(r, r, 2 * r, r, r, 2 * r, 0, 360);
        g.setColor(Color.YELLOW);
        g.fillEllipse(r, r, r + (r - 2), r, r, r + (r - 2), 0, 360);
        return result;
    }
}


Answer 2:

一个有效的,也许更简单的办法是通过使用该开源库Monits https://github.com/Monits/blackberry-commons

它包含BB应用中发现了几种常见的功能,是BB兼容4.6.1+

在其他方面,它提供了添加和显示标记,在它的上面,有和没有重点,可选择“打开”他们的能力的地图领域。 这使得更多的相似的API,它在其他智能手机如iPhone或Android找到。

该文档是相当不错的,和维基甚至有关于如何实现它的教程https://github.com/Monits/blackberry-commons/wiki/CustomMap



文章来源: How to show more than one location in Blackberry MapField?