1

An app that I work on has a bus prediction feature. In this feature we have a Google Map the displays a selected bus route as a Polyline and uses custom flat Markers. The problem is that on our Sony Xperia M (C1904) (running Jelly Bean 4.3), the Markers are huge. (Screenshots below. Had to black some stuff out because of corporate) I'm including screenshots of the same code on a Nexus 5 (running KitKat 4.4.4) and a Nexus 6P (running Marshmallow 6.0.1).

Sony Xperia M (Jelly Bean)

Xperia M Screenshot

Nexus 5 (KitKat)

Nexus 5 Screenshot

Nexus 6P (Marshmallow)

Nexus 6P Screenshot

As you can see, the higher-resolution screen has smaller markers and the relatively low resolution Xperia M has huge markers. Is there any way to make them appear to be the same size on every device?

Here's my Bitmap that I build:

public Bitmap getStopBitmapForRoute(BusDataProvider.BusRoute route) {
        BitmapFactory.Options myOptions = new BitmapFactory.Options();
        myOptions.inPreferredConfig = Bitmap.Config.ARGB_8888;// important
        myOptions.inMutable = true;

        Bitmap bitmap = Bitmap.createBitmap(BusFragment.outCircleRadius * 4, BusFragment.outCircleRadius * 4, Bitmap.Config.ARGB_8888);

        Log.d("Is Stop Bitmap Mutable?", bitmap.isMutable() + "");

        Canvas canvas = new Canvas(bitmap);

        Paint paint = new Paint();
        paint.setAntiAlias(true);
        paint.setColor(route.getRouteColor());
        canvas.drawCircle(BusFragment.outCircleRadius, BusFragment.outCircleRadius, BusFragment.outCircleRadius, paint);

        return bitmap;
    }

Here's the code that actually sets the Marker with its other options:

public Marker drawStop(CyRideDataProvider.StopLocation stop, GoogleMap map) {
        Marker marker;
        MarkerOptions markerOptions = new MarkerOptions()
           .icon(BitmapDescriptorFactory.fromBitmap(getStopBitmapForRoute(currentRoute)))
           .flat(true).anchor(0.25f, 0.25f).visible(true).position(stop.getLatLng());

        routeStopMarkers.put(marker = map.addMarker(markerOptions), stop);
        displayedStops.add(new Pair<>(marker, stop));
        return marker;
    }

Thanks in advance!

sonictt1
  • 2,906
  • 1
  • 15
  • 18
  • 1
    Using dimens.xml will probably solve it, see here: http://stackoverflow.com/a/16276351/4409409 – Daniel Nugent Mar 04 '16 at 17:22
  • @DanielNugent I think you're probably right but my boss's priorities have shifted so I haven't gotten a chance to try it yet. I'll let you know if it works as soon as I can so you can put it as an answer and I can accept it. Just letting you know that I haven't forgotten this question. ;D – sonictt1 Apr 15 '16 at 16:07

0 Answers0