google map api v2 add icon from url android

android, google-maps, google-maps-api-2, google-maps-markers

Solution

Use this method and use returned bitmap to display in map





public Bitmap getBitmapFromURL(String imageUrl) {
    try {
        URL url = new URL(imageUrl);
        HttpURLConnection connection = (HttpURLConnection) url.openConnection();
        connection.setDoInput(true);
        connection.connect();
        InputStream input = connection.getInputStream();
        Bitmap myBitmap = BitmapFactory.decodeStream(input);
        return myBitmap;
    } catch (IOException e) {
        e.printStackTrace();
        return null;
    }
}

Problem

I have a project that retrieves latitude and longitude from web service and I add them to google map markers. I want to add custom icon for the markers from url. ``` mMap.addMarker(new MarkerOptions() .position(new LatLng(dlat,Dlong)) .title(m.group(9)) .draggable(false) .snippet(m.group(1)+" "+m.group(10))); ``` How I can add `.icon` with a custom icon from a link?

Original source