vendredi 3 avril 2015

Adding custom marker to Google Map using TextView as Bitmap


Vote count:

0




I'm trying to programmatically add labels onto my Google Map using the Google Maps SDK for Android. My proposed solution is to use custom markers where the icon/image is basically a bitmap created from a TextView.


Here's what I have so far:



TextView label = new TextView(Activity.this);
label.setText(name);
label.setHeight(20);
label.setWidth(500);
label.setDrawingCacheEnabled(true);

if(label.getDrawingCache() != null) {
Bitmap labelImage = Bitmap.createBitmap(label.getDrawingCache());
Marker labelMarker = mMap.addMarker(new MarkerOptions()
.position(new LatLng(averageLatitude, averageLongitude))
.title(name)
.icon(BitmapDescriptorFactory.fromBitmap(labelImage))
);
}


However, label.getDrawingCache() is returning null so it's not able to draw the marker image. Any ideas?



asked 35 secs ago

codeman

1,288






Adding custom marker to Google Map using TextView as Bitmap

Aucun commentaire:

Enregistrer un commentaire