Set Image from drawable as marker in Google Map version 2

前端 未结 4 1192
难免孤独
难免孤独 2020-12-23 12:59

I am using this part of code to add a marker in a MapFragment in Google Map Version 2.

MarkerOptions op = new MarkerOptions();
op.position(point         


        
4条回答
  •  佛祖请我去吃肉
    2020-12-23 13:37

    This is how you can set a Drawable as a Marker.

    BitmapDescriptor icon = BitmapDescriptorFactory.fromResource(R.drawable.current_position_tennis_ball)
    
    MarkerOptions markerOptions = new MarkerOptions().position(latLng)
             .title("Current Location")
             .snippet("Thinking of finding some thing...")
             .icon(icon);
    
    mMarker = googleMap.addMarker(markerOptions);
    

    VectorDrawables and XML based Drawables do not work with this.

提交回复
热议问题