This question already has answers here:
Change marker size in Google Maps API v2
(5 answers)
Closed 4 years ago.
I am adding a custom marker to my map with code
marker =new MarkerOptions().icon(BitmapDescriptorFactory.fromResource(R.drawable.bus)));
but it appears too large and covers the whole screen
how to solve this issue.
you can resize programmatically
Solution 1:
int height = 100;
int width = 100;
BitmapDrawable bitmapdraw=(BitmapDrawable)getResources().getDrawable(R.drawable.bus);
Bitmap b=bitmapdraw.getBitmap();
Bitmap smallMarker = Bitmap.createScaledBitmap(b, width, height, false);
MarkerOptions marker = new MarkerOptions()
.title("Your title")
.icon(BitmapDescriptorFactory.fromBitmap(smallMarker));
googleMap.addMarker(marker);
Solution 2:
Simple you need to Change your Image into Small size.
Related
I am using Google Map API in an Android app and trying to rotate the map. I have already done it by changing the bearing value but the problem is that it rotates around the center of the screen.
CameraPosition bottomPos = new CameraPosition.Builder()
.bearing(bearing)
.build();
mainMap.animateCamera(CameraUpdateFactory.newCameraPosition(bottomPos));
I want to change its axis of rotation and make it rotate around a point at bottom of screen
Is there any function to change the axis of rotation of the map?
Anyway, you can use workaround like that - move map rotation center point to bottom of screen by creating MapView (MapFragment) twice as wide and as high and using margins align it position to center bottom like on a figure below:
In that case, with default:
CameraPosition bottomPos = new CameraPosition.Builder()
.bearing(bearing)
.build();
mainMap.animateCamera(CameraUpdateFactory.newCameraPosition(bottomPos));
your mainMap will turn around center of bottom of screen.
UPDATE:
Also you can use get current map center screen coordinates, then change y coordinate and get new screen center. Something like that:
...
CameraPosition bottomPos = new CameraPosition.Builder()
.bearing(bearing)
.build();
mainMap.moveCamera(CameraUpdateFactory.newCameraPosition(bottomPos));
LatLng mapCenter = mainMap.getCameraPosition().target;
Projection projection = mainMap.getProjection();
Point centerPoint = projection.toScreenLocation(mapCenter);
DisplayMetrics displayMetrics = new DisplayMetrics();
getWindowManager().getDefaultDisplay().getMetrics(displayMetrics);
int displayHeight = displayMetrics.heightPixels;
centerPoint.y = centerPoint.y - displayHeight / 2; // move center down
LatLng newCenterPoint = projection.fromScreenLocation(centerPoint);
mainMap.animateCamera(CameraUpdateFactory.newLatLngZoom(newCenterPoint, zoom));
...
Related: Customizing clickable area on a Marker in Google Maps v2 for Android
I have a number of icons inside an ArrayList, which are all custom icons with a drawable. The problem I have is that the clickable area is that of the default marker. I need to customize this clickable area to the same size of the default marker.
Here is my code to generate a set of markers on the map:
MarkerOptions options = new MarkerOptions();
for (Icon iconItem: icons) {
//Scale icon
int markerSize = 90;
Bitmap iconBitmap = BitmapFactory.decodeResource(getResources(), iconItem.resourceInt);
Bitmap scaledIconBitmap = Bitmap.createScaledBitmap(iconBitmap, markerSize, markerSize, false);
options.position(iconItem.location).title(iconItem.type);
Marker newMarker = gMap.addMarker(options);
newMarker.setIcon(BitmapDescriptorFactory.fromBitmap(scaledIconBitmap));
}
I get a .png from my server that represents a satellite image and I would put this image like a layer over the OpenStreetMap so I can see the street (under the satellite image) and the aerial photo on the same map.
I use this method
Drawable d = new BitmapDrawable(getResources(), bitmap);
bb = map.getBoundingBox();
Location SO = new Location(LocationManager.GPS_PROVIDER);
SO.setLatitude(bb.getLonWest());
SO.setLongitude(bb.getLatSouth());
Location NO = new Location(LocationManager.GPS_PROVIDER);
NO.setLatitude( bb.getLonWest());
NO.setLongitude(bb.getLatNorth());
Location NE = new Location(LocationManager.GPS_PROVIDER);
NE.setLatitude(bb.getLonEast());
NE.setLongitude(bb.getLatNorth());
float height = SO.distanceTo(NO);
float width = NE.distanceTo(NO);
Projection projection = map.getProjection();
int y = map.getHeight() / 2;
int x = map.getWidth() / 2;
GeoPoint geoPoint = (GeoPoint) projection.fromPixels(x, y);
deleteLayers(GroundOverlay.class);
GroundOverlay myGroundOverlay = new GroundOverlay();
myGroundOverlay.setImage(d);
myGroundOverlay.setPosition(geoPoint);
myGroundOverlay.setDimensions(width*0.94f, height*1.06f);
map.getOverlays().add(myGroundOverlay);
map.invalidate();
the problem is that the image always is stretch. my png cover only a part of my map (and it's ok beacuse our png is this way). When i move in the map the image stretching in all map but and it cover a part of map that it not rappresent.
Also, the image is not in the right place (look the red arrow).
How can i fix it?
Assuming your satellite image is limited to a portion of map you can use osmbonuspack GroundOverlay.
Probably this issue: https://github.com/MKergall/osmbonuspack/issues/273
Look at the hint about corrective coefficients.
It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 10 years ago.
I have 45 buttons which i have created by loop in java code. Now i need to set and change the background image depending on the user interaction and also need resize the image also depending on the button. It will be help-full for me if i can do everything for an image button in java.
How i can resize the background image of a button in java code.
If you want to resize an image on basis of the dimension of a Button, use getHeight() and getWidth() methods to get the size of the button and use following function to resize image for Button:
Resizing a Bitmap:
public Bitmap getResizedBitmap(Bitmap bm, int newHeight, int newWidth) {
int width = bm.getWidth();
int height = bm.getHeight();
float scaleWidth = ((float) newWidth) / width;
float scaleHeight = ((float) newHeight) / height;
// create a matrix for the manipulation
Matrix matrix = new Matrix();
// resize the bit map
matrix.postScale(scaleWidth, scaleHeight);
// recreate the new Bitmap
Bitmap resizedBitmap = Bitmap.createBitmap(bm, 0, 0, width, height, matrix, false);
return resizedBitmap;
}
Now you can use setBackgroundDrawable() or setBackgroundResource() methods on a Button object to change its Background Image and you can resize a Button via setHeight() and setWidth() methods.
Reference
Store arrays with the images and the data you want to use for each button, and use them while you are looping over the initialization of the ImageButtons.
Post some code for detailed help.
I'm looking for help developing (or a library) which can allow me to merge together multiple images into one imageview.
My application is grouping together interactions between users, instead of displaying them singularly, and therefore I would like to merge all of their avatars, so that one adapter cell visualizes a "group".
A fantastic example of this is done on facebook.com's chat as such:
My question is, how can I provide this functionality in Android / Java? Presumably, it could a number of images between 1 and 4. Please let me know of any advice you can give :)
You can use MultiImageView.
Add dependency in app.gradle:
compile 'com.github.stfalcon:multiimageview:0.1'
Add MultiImageView to layout xml file
<com.stfalcon.multiimageview.MultiImageView
android:id="#+id/iv"
android:layout_width="100dp"
android:layout_height="100dp"/>
In java class find view by id:
final MultiImageView multiImageView = (MultiImageView) findViewById(R.id.iv);
For adding image to MultiImageView use method addImage(Bitmap bitmap). For exapple:
multiImageView.addImage(BitmapFactory.decodeResource(getResources(), R.drawable.avatar1));
For setting shape of MultiImageView use method setShape(MultiImageView.Shape shape).
multiImageView.setShape(MultiImageView.Shape.RECTANGLE);//Rectangle with round corners
multiImageView.setShape(MultiImageView.Shape.CIRCLE);//Circle
multiImageView.setShape(MultiImageView.Shape.NONE);//Without shape
Check github link for more information:
I think it is what you needed
You should overlap bitmaps onto another bitmap. A first approach are this:
Merge bitmaps
You can play with matrix and orders and sizes for a complex UI.
i know it's an old question but maybe it will help somebody else.
private Bitmap mergeThemAll(List<Bitmap> orderImagesList) {
Bitmap result = null;
if (orderImagesList != null && orderImagesList.size() > 0) {
// if two images > increase the width only
if (orderImagesList.size() == 2)
result = Bitmap.createBitmap(orderImagesList.get(0).getWidth() * 2, orderImagesList.get(0).getHeight(), Bitmap.Config.ARGB_8888);
// increase the width and height
else if (orderImagesList.size() > 2)
result = Bitmap.createBitmap(orderImagesList.get(0).getWidth() * 2, orderImagesList.get(0).getHeight() * 2, Bitmap.Config.ARGB_8888);
else // don't increase anything
result = Bitmap.createBitmap(orderImagesList.get(0).getWidth(), orderImagesList.get(0).getHeight(), Bitmap.Config.ARGB_8888);
Canvas canvas = new Canvas(result);
Paint paint = new Paint();
for (int i = 0; i < orderImagesList.size(); i++) {
canvas.drawBitmap(orderImagesList.get(i), orderImagesList.get(i).getWidth() * (i % 2), orderImagesList.get(i).getHeight() * (i / 2), paint);
}
} else {
Log.e("MergeError", "Couldn't merge bitmaps");
}
return result;
}
Addition to the answer by Anton Bevza
Their library has some disadvantages that are fixed in the fork
Add dependency in app.gradle:
implementation 'com.github.martipello:MultiImageView:1.0.8.2'
Add MultiImageView to layout xml file
<com.sealstudios.multiimageview.MultiImageView
android:id="#+id/iv"
android:layout_width="100dp"
android:layout_height="100dp"
app:shape="circle" />
For setting shape of MultiImageView use attributes in layout xml file
app:shape="circle" //Circle
app:shape="rectangle" //Rectangle with round corners
app:shape="none" //Without shape
Also you can change shape by using method:
multiImageView.setShape(MultiImageView.Shape.RECTANGLE);//Rectangle with round corners
multiImageView.setShape(MultiImageView.Shape.CIRCLE);//Circle
multiImageView.setShape(MultiImageView.Shape.NONE);//Without shape
In java class find view by id:
final MultiImageView multiImageView = findViewById(R.id.iv);
For adding image to MultiImageView use method addImage(Bitmap bitmap). For example:
multiImageView.addImage(BitmapFactory.decodeResource(getResources(), R.drawable.avatar));
//or
Bitmap bitmap = MediaStore.Images.Media.getBitmap(getContentResolver(), ImageUri);
multiImageView.addImage(bitmap);