谷歌地图API V2如何在安卓中使用URL添加图标

3

我有一个项目,从Web服务中检索纬度和经度并将它们添加到Google地图标记中。我想为标记从URL添加自定义图标。

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

我该如何使用自定义图标链接添加 .icon

这里是包含代码片段的详细答案: https://stackoverflow.com/a/61929527/8663316 - Faizan Haidar Khan
这里是包含代码片段的详细答案: https://stackoverflow.com/a/61929527/8663316 - Faizan Haidar Khan
2个回答

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

谢谢您的回答,我成功地按照您的答案完成了它。 - Kostaras
请问您能否解释一下您的代码片段如何根据问题更改标记图标?谢谢。 - onexf
我已经实现了这个功能,虽然它在添加了permitAll strictmode threadpolicy后可以工作,但是速度非常慢,特别是在有许多标记的情况下... 这个过程基本上不推荐吗? - Grant

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

这对我有用


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接