【问题标题】:google map api v2 add icon from url android谷歌地图 api v2 从 url android 添加图标
【发布时间】:2014-07-07 02:47:19
【问题描述】:

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

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

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

【问题讨论】:

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


【解决方案1】:
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;
    }
}

【讨论】:

  • 感谢您的回答,我设法与您的回答类似
  • 您能否解释一下您的代码 sn-p 如何用于更改与问题相关的标记图标?谢谢。
  • 我实现了这个,当它工作时(在添加 permitAll strictmode threadpolicy 之后)它非常慢,尤其是有很多标记......这个过程基本上不推荐吗?
【解决方案2】:
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();
                    }

这对我有用

【讨论】:

    猜你喜欢
    • 2014-01-15
    • 1970-01-01
    • 1970-01-01
    • 2012-11-29
    • 2016-10-12
    • 1970-01-01
    • 2013-01-21
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多