blackberrygpsmapsjsr179

How to show our own icon in BlackBerry Map?


I want to know how to use our own logo to show the particular place in BBMap? Can anyone knows how to do this ?


Solution

  • BlackBerry Map

    It's not possible in Blackberry Map to show custom icon for POI.
    Things you can include in Location on Blackberry Map:

    See What Is - BlackBerry Maps Location Document Format

    Also see How To - Invoke BlackBerry Maps

    Using MapField

    As an alternative you can try MapField + manager/screen paint override.

    Custom extension for MapField:

    class CustomMapField extends MapField {
        Bitmap mIcon;
        XYRect mDest;
    
        public void moveTo(Coordinates coordinates) {
            super.moveTo(coordinates);
            mDest = null;
        }
    
        protected void paint(Graphics graphics) {
            super.paint(graphics);
            if (null != mIcon) {
                if (null == mDest) {
                    XYPoint fieldOut = new XYPoint();
                    convertWorldToField(getCoordinates(), fieldOut);
                    int imgW = mIcon.getWidth();
                    int imgH = mIcon.getHeight();
                    mDest = new XYRect(fieldOut.x - imgW / 2, 
                    fieldOut.y - imgH, imgW, imgH);
                }
                graphics.drawBitmap(mDest, mIcon, 0, 0);
            }
        }
    }
    

    Example of use:

    class Scr extends MainScreen {
        CustomMapField mMapField;
        Coordinates mCoordinates;
        public Scr() {
            LocationProvider provider = null;
            Location location = null;
            try {
                provider = LocationProvider.getInstance(null);
            } catch (LocationException e) {
                e.printStackTrace();
            }
            try {
                location = provider.getLocation(-1);
            } catch (LocationException e) {
                e.printStackTrace();
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            mCoordinates = location.getQualifiedCoordinates();
            add(new LabelField("Latitude: "
                    + String.valueOf(Coordinates.convert(
                    mCoordinates.getLatitude(),
                    Coordinates.DD_MM_SS))));
            add(new LabelField("Longitude: "
                    + String.valueOf(Coordinates.convert(
                    mCoordinates.getLongitude(), 
                    Coordinates.DD_MM_SS))));
            mMapField = new CustomMapField();
            mMapField.mIcon = Bitmap.getBitmapResource("poi_icon.png");
            mMapField.moveTo(mCoordinates);
            add(mMapField);
        }
    }
    

    See also
    Using MapComponent in Blackberry
    GPS and BlackBerry Maps Development Guide

    Prepare GPS data

    If it's real device, be sure GPS is available and turned on.
    If it's simulator, then before you start program use simulator menu -> simulate -> GPS Location to set GPS data.
    Other option is hardcode your own Coordinats and use them without GPS:

        double latitude = 51.507778;
        double longitude = -0.128056;
        Coordinates mCoordinates = new  Coordinates(latitude, longitude, 0);