Gustavo Baiocchi Costa
Gustavo Baiocchi Costa

Reputation: 1448

Android - Dynamic Custom Map Marker

I am using Google Maps V2. I am trying to create custom markers at run time with images and text that come from a server. I would like to have a balloon like marker that would stretch accordingly to the size of the image bitmap with a text on top of it.

For example:

Lets say I have a balloon image like this:

enter image description here

A image like this:

enter image description here

What I am trying to achieve would be to place this image inside the balloon with some text above the image, something like this:

enter image description here

If it is possible, how can I achieve this?

I have to place the final image as a icon for the marker option in google maps, something like this:

// Resource ID from the drawable folder
int balloon_id = getResources().getInteger(R.drawable.balloon_image);

// A bitmap image that came from the server (I got this done)
Bitmap image_from_server;

// Some text that came from the server (I got this done too)
String some_text;

// A method that will return the final resulted image to be placed to the marker options
// What I need is to find out the work out of this method (This is where I am struggling
BitmapDescriptor result_image = some_method(balloon_id, image_from_server, some_text);

// Marker Options for the custom marker
MarkerOptions mo = new MarkerOptions()
                  .position(latlng)
                  .icon(result_image);

// Then I can have my marker
Marker my_marker = google_map.addMarker(mo);

I have looked into StackOverflow for similar solutions to no avail. The accepted answer would contain the method that I am struggling to build or a very good direction to where I can achieve the solution on my own (but please take a look at the parameters of my method and what it returns, if I need to adjust that is not a big problem), thanks in advance!

Upvotes: 0

Views: 1524

Answers (1)

kaho
kaho

Reputation: 4784

Well, you can draw your images on canvas, overlaying each other. This function would do just that.

so you just put your images/text in the correct position and create them as bitmap, then overlay them in order.

private Bitmap overlay(Bitmap bmp1, Bitmap bmp2) {
    Bitmap bmOverlay = Bitmap.createBitmap(bmp1.getWidth(), bmp1.getHeight(), bmp1.getConfig());
    Canvas canvas = new Canvas(bmOverlay);
    canvas.drawBitmap(bmp1, new Matrix(), null);
    canvas.drawBitmap(bmp2, new Matrix(), null);
    return bmOverlay;
}

Upvotes: 1

Related Questions