自定义 google 地图标记图标未按预期工作。它同时显示加载的位图和红色引脚

Custom google map marker icon is not working as expected. It shows both the loaded bitmap and the red pin

我关注了这个answer

这是我的代码

Marker marker = mMap.addMarker(markerOptions);
    PicassoMarker picassoMarker = new PicassoMarker(marker);
    Picasso.with(getActivity()).load(url).into(picassoMarker);


    mMap.addMarker(markerOptions);
    mMap.moveCamera(CameraUpdateFactory.newLatLng(sydney));

它像老板一样工作,但问题是它同时显示红色图钉和加载的位图

您可以像这样设置自定义标记图标

MarkerOptions markerOptions = new MarkerOptions().icon(BitmapDescriptorFactory.fromResource(R.drawable.icon_location));

如果您从服务器获取标记图像,那么您应该首先使用 AsyncTask 在后台线程中下载图像,然后您可以将位图设置为标记

您添加了两次标记。第一次使用 Picasso 更改图标,但第二次使用 MarkerOptions 添加默认图标。只需删除这一行:

mMap.addMarker(markerOptions);