This question already has an answer here:
I am developing an Android Application where I'm using Google Map API v2. I need to show the user location on a map with custom markers.
Each marker will show the picture of the user from an URL. The image must be downloaded in asynchronous mode from the server. See the attached screenshot for an example.
How do I add an image and custom information in the marker?
From lambda answer, I have made something closer to the requirements.
In the Google Maps API v2 Demo there is a
MarkerDemoActivity
class in which you can see how a custom Image is set to a GoogleMap.As this just replaces the marker with an image you might want to use a
Canvas
to draw more complex and fancier stuff:This draws the Canvas
canvas1
onto theGoogleMap mMap
. The code should (mostly) speak for itself, there are many tutorials out there how to draw aCanvas
. You can start by looking at the Canvas and Drawables from the Android Developer page.Now you also want to download a picture from an URL.
You must download the image from an background thread (you could use AsyncTask or Volley or RxJava for that).
After that you can replace the
BitmapFactory.decodeResource(getResources(), R.drawable.user_picture_image)
with your downloaded imagebmImg
.I hope it still not too late to share my solution. Before that, you can follow the tutorial as stated in Android Developer documentation. To achieve this, you need to use Cluster Manager with
defaultRenderer
.Create an object that implements
ClusterItem
Create a default renderer class. This is the class that do all the job (inflating custom marker/cluster with your own style). I am using Universal image loader to do the downloading and caching the image.
Apply cluster manager in your activity/fragment class.
Result
The alternative and easier solution that i also use is to create custom marker layout and convert it into a bitmap.
view_custom_marker.xml
Convert this view into bitmap by using the code below
Add your custom marker in on Map ready callback.
For more details please follow the link below
How to create custom marker using layout?