Hi i am developing mapview using v2,
From MarkerOptions object i am getting an icon, like...
MarkerOptions mo = markersList.get(pos);
BitmapDescriptor icon = mo.getIcon(); //Gets the custom icon set for this MarkerOptions object.
ImageView logo;
//how to assign icon to textview like using below code
logo.setBackgroundResource(icon) // It is not taking directly (BitmapDescriptor icon)
Please help. Thank you.
Related
i'm trying to show text for all markers.
I've seen this solution:
http://googlemaps.github.io/android-maps-utils/
And checked the
http://googlemaps.github.io/android-maps-utils/javadoc/
I've succeeded to get to this situation:
But as you can see the text is on the icon, and I want it to have a bit of margin button - and I can't figure out how to do it.
This is the code I used to make the marker:
Context context = getApplicationContext();
TextView text = new TextView(context);
text.setText(pilotName);
text.setTextSize(18);
text.setTypeface(null, Typeface.BOLD);
text.setTextColor(getResources().getColor(R.color.colorBlack));
IconGenerator generator = new IconGenerator(context);
generator.setContentPadding(20,20,0,0);
generator.setBackground(context.getDrawable(R.drawable.aircraft));
generator.setContentView(text);
Bitmap icon = generator.makeIcon();
MarkerOptions tp = new MarkerOptions().position(latLng).icon(BitmapDescriptorFactory.fromBitmap(icon));
mMap.addMarker(tp);
I've also tried: text.setPadding(40, 40, 0, 0);
And generator.setContentPadding(20,20,0,0);
to see if it solves it... and it didn't work
How can I solve it? Thanks
I have added the text to the marker using marker options
TextView text = new TextView(context);
text.setText(" "+assetName+" ");
text.setTextColor(context.getResources().getColor(R.color.color_white));
IconGenerator generator = new IconGenerator(context);
generator.setColor(context.getResources().getColor(R.color.colorAccent));
generator.setContentView(text);
generator.setRotation(360);
Bitmap icon = generator.makeIcon();
MarkerOptions tp = new MarkerOptions().position(latLng).icon(BitmapDescriptorFactory.fromBitmap(icon));
MapFragment.googleMap.addMarker(tp);
Now i want the text "iqbal" on the marker when i click on it.
You can't get the text from the marker because your text is inside a generated bitmap. However, you can save the text and anything you can need in the marker tag:
TextView text = new TextView(context);
text.setText(" "+assetName+" ");
text.setTextColor(context.getResources().getColor(R.color.color_white));
IconGenerator generator = new IconGenerator(context);
generator.setColor(context.getResources().getColor(R.color.colorAccent));
generator.setContentView(text);
generator.setRotation(360);
Bitmap icon = generator.makeIcon();
MarkerOptions tp = new MarkerOptions().position(latLng)
.icon(BitmapDescriptorFactory.fromBitmap(icon))
.tag(text);
Marker marker = MapFragment.googleMap.addMarker(tp);
And then
String text = marker.getTag().toString()
Marker options doesnt have tag attribute. So you have to give the tag feature to the marker
TextView text = new TextView(context);
text.setText("Some Text Here");
text.setTypeface(Typeface.DEFAULT_BOLD);
IconGenerator generator = new IconGenerator(context);
generator.setBackground(context.getDrawable(R.color.cyan_800_overlay));
generator.setContentView(text);
generator.setStyle(IconGenerator.STYLE_BLUE);
Bitmap icon = generator.makeIcon();
MarkerOptions tp = new MarkerOptions()
.position(latLng)
.icon(BitmapDescriptorFactory.fromBitmap(icon));
Marker marker = mMap.addMarker(tp);
marker.setTag(Some Tag Here);
I been using google map utils for a couple of days now and it seemed so fine.
This is code im using to add a marker with a custom layout file to the map.
IconGenerator mIconGenerator = new IconGenerator(getApplicationContext());
View mView = getLayoutInflater().inflate(R.layout.map_location_label, null);
TextView mInfoWindowText = (TextView) mView.findViewById(R.id.location);
mInfoWindowText.setText(Takzy.pickupLocationText);
mIconGenerator.setContentView(mView);
mIconGenerator.setRotation(-90);
mIconGenerator.setContentRotation(90);
mIconGenerator.setContentPadding(0, 0, 0, 0);
view.Bitmap mBitmapPickupLocation = mIconGenerator.makeIcon();
Bitmap mBitmapDestinationLocation = mIconGenerator.makeIcon(Takzy.destinationLocationText + " >");
// add the pickup marker to map
mMap.addMarker(
new MarkerOptions().title(Takzy.pickupLocationText)
.position(Takzy.pickupLatLng)
.icon(BitmapDescriptorFactory
.fromBitmap(mBitmapPickupLocation))
.anchor(mIconGenerator.getAnchorU(), mIconGenerator.getAnchorV()));
Everything is okay but as you can see, my text gets cut from the marker label. I have tried googling, read the docs over and over, and none of them worked.
it will work fine if I do not rotate the marker. but I need my marker rotated.
Can someone point out what might be the issue is?
I am trying to animate change marker position in Xamarin android Google Map
var markerWithIcon = new MarkerOptions();
markerWithIcon.SetPosition(new LatLng(e.Latitude, e.Longitude));
var marker = googleMap.AddMarker(markerWithIcon);
Setting its position
marker.Position = new LatLng(e.Latitude, e.Longitude);
How to change position with linear animation? Thanks in advance.
I need to add icon to my map, something like image below :
this is my code :
MarkerOptions marker = new MarkerOptions().position(location).title("resturan")
.icon(BitmapDescriptorFactory.fromResource(R.drawable.a2));
I manage to add icon to my map but it's just an icon with no border and it doesn't look nice , in the above image , there is a border around each image , this is what i need
How can I add this border to my icons ?
thank you
Take a look at this blog post I wrote on how to put images inside the InfoWindow in an asynchronous way:
Guide: Google Maps V2 for Android : Update InfoWindow with an Image Asynchronously
You can see there how to specify a layout for your InfoWindow as well, in the layout you could add the borders to your image using the margins attribute.
This way you can customize your map icon before apply in the map.
public Bitmap createDrawableFromView(Context context) {
View marker = ((LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE)).
inflate(R.layout.map_popup, your_parent_layout,false);
TextView tv_location_name = (TextView) marker.findViewById(R.id.tv_location_name);
TextView tv_event_status = (TextView) marker.findViewById(R.id.tv_event_status);
TextView tv_event_name = (TextView) marker.findViewById(R.id.tv_event_name);
DisplayMetrics displayMetrics = new DisplayMetrics();
((Activity) context).getWindowManager().getDefaultDisplay().getMetrics(displayMetrics);
marker.measure(displayMetrics.widthPixels, displayMetrics.heightPixels);
marker.layout(0, 0, displayMetrics.widthPixels, displayMetrics.heightPixels);
marker.buildDrawingCache();
Bitmap bitmap = Bitmap.createBitmap(marker.getMeasuredWidth(), marker.getMeasuredHeight(), Bitmap.Config.ARGB_8888);
Canvas canvas = new Canvas(bitmap);
marker.draw(canvas);
return bitmap;
}