google map api v2从url android添加图标

时间:2014-05-19 08:10:03

标签: android google-maps google-maps-markers google-maps-api-2

我有一个从Web服务检索纬度和经度的项目,我将它们添加到谷歌地图标记。我想从网址添加标记的自定义图标。

    mMap.addMarker(new MarkerOptions()
                    .position(new LatLng(dlat,Dlong))
                    .title(m.group(9))
                    .draggable(false)                                           
                    .snippet(m.group(1)+" "+m.group(10)));

如何使用链接中的自定义图标添加.icon

2 个答案:

答案 0 :(得分:3)

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;
    }
}

答案 1 :(得分:0)

try{
                        URL url = new URL(Lurl);
                        /** Creating an http connection to communcate with url */
                        HttpURLConnection urlConnection = (HttpURLConnection) url.openConnection();
                        /** Connecting to url */
                        urlConnection.connect();
                        /** Reading data from url */
                        iStream = urlConnection.getInputStream();
                        /** Creating a bitmap from the stream returned from the url */
                        bitmap = BitmapFactory.decodeStream(iStream);

                    }catch(Exception e){
                        Log.d("Exception while downloading url", e.toString());
                    }finally{
                        iStream.close();
                    }

这对我有用