Before asking this question, I reviewed many links
I'm parsing an xml from a web, and from this xml, get the longitude, latitude and name for a marker that I add to my map (v2) on android app
so far everything works perfectly.
mMap.addMarker(new MarkerOptions()
.position(new LatLng(dLat, dLon)) // lat and lon from the xml of the web
.title(NAME_OF_MARKER));
This xml also includes a field with the url of the small image to display the marker
<marker>
<lat>40.758895</lat>
<lon>-73.985131</lon>
<name>My Point</name>
<thumb>http://research.cbei.psu.edu/images/uploads/research-digest/general/1.CityIcon.png</thumb>
</marker>
I understand that the image of the xml should be loaded into a BitMap, and this BitMap put it as marker icon:
mMap.addMarker(new MarkerOptions()
.position(new LatLng(dLat, dLon))
.title(NAME_OF_MARKER))
.setIcon(BitmapDescriptorFactory.fromBitmap(bmp));
I am using an AsyncTask to load the url and assign it to a bitmap:
Bitmap bmp;
Canvas canvas1;
//...
public class markers extends AsyncTask<String, Void, String> {
protected void onPreExecute() {
Bitmap.Config conf = Bitmap.Config.ARGB_8888;
bmp = Bitmap.createBitmap(80, 80, conf);
}
public String doInBackground(String... urls) {
try {
URL url = new URL(MY_THUMB); //url of the image parser from the xml ("http://research.cbei.psu.edu/images/uploads/research-digest/general/1.CityIcon.png")
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
conn.setDoInput(true);
conn.connect();
InputStream is = conn.getInputStream();
bmp = BitmapFactory.decodeStream(is);
} catch (IOException e) {
}
//...
... And before creating the marker on the map:
canvas1 = new Canvas(bmp);
Paint color = new Paint();
color.setTextSize(35);
color.setColor(Color.BLACK);
//modify canvas
canvas1.drawBitmap(bmp, 0, 0, color);
canvas1.drawText("User Name!", 30, 40, color);
mMap.addMarker(new MarkerOptions()
.position(new LatLng(dLat, dLon))
.title(NAME_OF_MARKER))
.setIcon(BitmapDescriptorFactory.fromBitmap(bmp));
}
..but Never works. Everything loads fine, but never the icon is displayed.
I have carefully read many threads related like this:
Android load from URL to Bitmap
How to get bitmap from a url in android?
But I get it working, of course I have included the necessary permissions in the manifest, internet, write external, etc, but without success.
I would greatly appreciate any help, I have tested hundreds of ways.
Greetings and thank you in advance