简体   繁体   English

更改谷歌 Map 标记图标

[英]Change Google Map marker icon

I wrote this code in onMapReady and call a function to change Google Map icon but it does not work.我在onMapReady中编写了此代码并调用 function 来更改 Google Map 图标,但它不起作用。 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"嘿,我找到了这个,它的工作:D 用“BitmapDescriptorFactory.fromResource”替换 function

   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));

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM