Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

google map api v2 add icon from url android

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?

like image 563
Kostaras Avatar asked Mar 08 '26 21:03

Kostaras


1 Answers

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;
    }
}
like image 116
Jogendra Gouda Avatar answered Mar 10 '26 14:03

Jogendra Gouda