4

I have searched in google but i couldn't get it. I need this type where values to be in markers

enter image description here

I couldn't get an idea how to do like what is displayed above.

GoogleMap gm;

    gm = ((SupportMapFragment) (getSupportFragmentManager()
                .findFragmentById(R.id.map))).getMap();

    gm.setOnInfoWindowClickListener(this);
    gm.addMarker(new MarkerOptions()
                            .title(jsonObj.getString("project_name"));

   @Override
   public void onInfoWindowClick(final Marker marker) {

   String name = marker.getTitle(); // this displays when marker window gets tap

}

But the above code just displays when I tap on marker window. I just want to display like above iamge link. How to do that.please help to solve the issue.

Thanks in advance.

Raghunandan
  • 132,755
  • 26
  • 225
  • 256

3 Answers3

7

Use android map utils library

Here's the link to the website and go through the video posted.

http://googlemaps.github.io/android-maps-utils/

1.Downlaod the library from

github.com/googlemaps/android-maps-utils

2.To use check this link

Using android-maps-utils with ADT

  IconGenerator tc = new IconGenerator(this);
  Bitmap bmp = tc.makeIcon("hello"); // pass the text you want.

Then set the bitmap to the map object

  .icon(BitmapDescriptorFactory.fromBitmap(bmp))); 

Snap

enter image description here

Community
  • 1
  • 1
Raghunandan
  • 132,755
  • 26
  • 225
  • 256
3

For a full free drawing of the marker icon the code may look like the following. In this case only the text is the content of the marker. But you can draw anything into the canvas. Just make sure to adapt the size.

public BitmapDescriptor getTextMarker(String text) {

    Paint paint = new Paint();
    /* Set text size, color etc. as needed */
    paint.setTextSize(24);

    int width = (int)paint.measureText(text);
    int height = (int)paint.getTextSize();

    paint.setTextAlign(Align.CENTER);
    // Create a transparent bitmap as big as you need
    Bitmap image = Bitmap.createBitmap(width, height, Config.ARGB_8888);
    Canvas canvas = new Canvas(image);
    // During development the following helps to see the full
    // drawing area:
    canvas.drawColor(0x50A0A0A0);
    // Start drawing into the canvas
    canvas.translate(width / 2f, height);
    canvas.drawText(text, 0, 0, paint);
    BitmapDescriptor icon = BitmapDescriptorFactory.fromBitmap(image);
    return icon;
}

Then use this method when building the marker options:

mMap.addMarker(new MarkerOptions()
.position(new LatLng(lati, longi))
.icon(getTextMarker("some text"));
user2808624
  • 2,502
  • 14
  • 28
  • Hi, what is the paint object here. – shyam.y Jan 18 '15 at 14:40
  • It's an instance of Paint, which you have prepared before (as a member variable) with the color, text size and so on, you wish to use in the marker. To avoid lots of object allocations you usually prepare such objects only once in Android. – user2808624 Jan 18 '15 at 18:20
  • Thanks, I worked on it, but marker is not displaying on map. Can u guide me please. I want to create seperate marker icons with marker count as text with different color for background. – shyam.y Jan 18 '15 at 18:29
2

According to the documents of Google Maps for Android V2:

An info window allows you to display information to the user when they tap on a marker on a map. By default, an info window is displayed when a user taps on a marker if the marker has a title set. Only one info window is displayed at a time. If a user clicks on another marker, the current window will be hidden and the new info window will be displayed. You can show an info window programmatically by calling showInfoWindow() on the target marker. An info window can be hidden by calling hideInfoWindow().

You can show the info window like this:

Marker marker = myMap.addMarker(new MarkerOptions()
                     .position(latLng)
                     .title("Title")
                     .snippet("Snippet")
                     .icon(BitmapDescriptorFactory
                     .fromResource(R.drawable.marker)));

marker.showInfoWindow();

I hope it will work for you.

GrIsHu
  • 29,068
  • 10
  • 64
  • 102
  • info windows is displayed when user taps on the same however op wants the image displayed without the same. – Raghunandan Oct 08 '13 at 10:03
  • thanks @Raghunandan you saved my time a lot.. Thanks once again. And a small doubt is Is it possible to change color of that marker icon? It is displaying white. –  Oct 08 '13 at 10:07
  • @Tinkerbell yes you can have blue orange green and red. – Raghunandan Oct 08 '13 at 10:08
  • @Tinkerbell `Bitmap bmp = drawTextToBitmap(this,R.drawable.bubble_green,"mytext")`. Now set the bitmap to the map object .`icon(BitmapDescriptorFactory.fromBitmap(bmp)))` – Raghunandan Oct 08 '13 at 10:12