How to create a custom-shaped bitmap marker with Android map API v2 -


i developing android application i'm using google map api v2. need show user location on map custom markers.

each marker show picture of user url. image must downloaded in asynchronous mode server. see attached screenshot example.

how add image , custom information in marker?

enter image description here

in google maps api v2 demo there markerdemoactivity class in can see how custom image set googlemap.

// uses custom icon. msydney = mmap.addmarker(new markeroptions()     .position(sydney)     .title("sydney")     .snippet("population: 4,627,300")     .icon(bitmapdescriptorfactory.fromresource(r.drawable.arrow))); 

as replaces marker image might want use canvas draw more complex , fancier stuff:

bitmap.config conf = bitmap.config.argb_8888; bitmap bmp = bitmap.createbitmap(80, 80, conf); canvas canvas1 = new canvas(bmp);  // paint defines text color, stroke width , size paint color = new paint(); color.settextsize(35); color.setcolor(color.black);  // modify canvas canvas1.drawbitmap(bitmapfactory.decoderesource(getresources(),     r.drawable.user_picture_image), 0,0, color); canvas1.drawtext("user name!", 30, 40, color);  // add marker map mmap.addmarker(new markeroptions()     .position(user_position)     .icon(bitmapdescriptorfactory.frombitmap(bmp))     // specifies anchor @ particular point in marker image.     .anchor(0.5f, 1)); 

this draws canvas canvas1 onto googlemap mmap. code should (mostly) speak itself, there many tutorials out there how draw canvas. can start looking @ canvas , drawables android developer page.

now want download picture url.

url url = new url(user_image_url); httpurlconnection conn = (httpurlconnection) url.openconnection();    conn.setdoinput(true);    conn.connect();      inputstream = conn.getinputstream(); bmimg = bitmapfactory.decodestream(is);  

you must download image background thread (you use asynctask or volley that).

after can replace bitmapfactory.decoderesource(getresources(), r.drawable.user_picture_image) downloaded image bmimg.


Comments

Popular posts from this blog

java - Jmockit String final length method mocking Issue -

asp.net - Razor Page Hosted on IIS 6 Fails Every Morning -

c++ - wxwidget compiling on windows command prompt -