Reputation:
I have searched in google but i couldn't get it. I need this type where values to be in markers
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.
Upvotes: 4
Views: 10507
Reputation: 2530
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"));
Upvotes: 3
Reputation: 133560
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
Upvotes: 7
Reputation: 23638
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.
Upvotes: 2