I wrote this code in onMapReady
and call a function to change Google Map icon but it does not work. here the code:
public void onMapReady(final GoogleMap googleMap) {
googleMap.addMarker(new MarkerOptions()
.position(lng)
.icon(getBitmapDescriptor())
.title("Marker in Mashhad"));
}
private BitmapDescriptor getBitmapDescriptor() {
Drawable vectorDrawable = ResourcesCompat.getDrawable(getResources(), R.drawable.round_accent, null);
Bitmap bitmap = Bitmap.createBitmap(vectorDrawable.getIntrinsicWidth(),vectorDrawable.getIntrinsicHeight(), Bitmap.Config.ARGB_8888);
Canvas canvas = new Canvas(bitmap);
vectorDrawable.setBounds(0, 0, canvas.getWidth(), canvas.getHeight());
vectorDrawable.draw(canvas);
return BitmapDescriptorFactory.fromBitmap(bitmap);
}
Hey i found this and it`s work:D Replace the function with "BitmapDescriptorFactory.fromResource"
googleMap.addMarker(new MarkerOptions()
.position(lng)
.icon(BitmapDescriptorFactory.fromResource(R.drawable.bazaarteh_logo_text))
.title("Marker in Mashhad"));
googleMap.animateCamera(CameraUpdateFactory.newLatLngZoom(lng, 12.0f));
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.