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 Marker
s. The problem is that on our Sony Xperia M (C1904) (running Jelly Bean 4.3), the Marker
s 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)
Nexus 5 (KitKat)
Nexus 6P (Marshmallow)
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!