I want to add picture to marker in google maps. I want to show after clicked on marker picture and on right side of that picture some text. I create marker using this code:
Marker melbourne = map.addMarker(new MarkerOptions()
.position(new LatLng(lblat,
lbLong))
.title("Melbourne")
.snippet("Population: 4,137,400")
.icon(BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_AZURE)));
but in that solution I have only title and snippet. How do marker on my way?
You will have to inflate your own layout of the InfoWindow
with an InfoWindowAdapter
. See the documentation here .
Here's a little example (I have this as an inner class in my map Activity
):
class MyInfoWindowAdapter implements InfoWindowAdapter {
private final View v;
MyInfoWindowAdapter() {
v = getLayoutInflater().inflate(R.layout.infowindow,
null);
}
@Override
public View getInfoContents(Marker marker) {
ImageView icon = (ImageView) v.findViewById(R.id.icon);
// set some bitmap to the imageview
return v;
}
@Override
public View getInfoWindow(Marker marker) {
// TODO Auto-generated method stub
return null;
}
}
And in your map Activity
gmap.setInfoWindowAdapter(new MyInfoWindowAdapter());
Good luck :)
If you want to customize your marker by using an image, you can add this image to the drawable folder, then:
mMap.addMarker(new MarkerOptions()
.position(marq).icon(BitmapDescriptorFactory.fromResource((R.drawable.thenameofyourimage)))
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.