Android Google Maps API v2 - how to change marker icon

后端 未结 8 1160
青春惊慌失措
青春惊慌失措 2021-01-31 16:34

I am trying to change marker icon. I get the image from one server directory.

When I put break point every time the \"bit\" result is null. And when I run t

8条回答
  •  太阳男子
    2021-01-31 16:56

    In the newer versions of GoogleMaps for Android you can't call .setIcon() on a MarkerOptions object. Instead you have to add the marker options to the map which will give you a Marker on which you can then change the icon.

    In Kotlin the code would look like this:

    val markerOptions = MarkerOptions()
    markerOptions.position(LatLng(40.419900, -111.880767))
    val marker: Marker?  = googleMap?.addMarker(markerOptions)
    val bitmapDescriptor = BitmapDescriptorFactory.fromResource(R.drawable.marker_customer_symbol)
    marker?.setIcon(bitmapDescriptor)
    

提交回复
热议问题