0

我正在尝试制作一个 android 应用程序来向用户显示附近的餐馆。我有一个谷歌地图显示并在餐厅中添加标记。当用户点击标记时,它会显示信息。餐厅名称、评级和图标(如果存在)。我正在使用地方搜索,我得到了每家餐厅的信息。它的工作,但当我试图显示它显示为空的图标。

听到的是我试图获取 reaturant 图像的代码

private InputStream OpenHttpConnection(String urlString) 
        throws IOException
        {
            InputStream in = null;
            int response = -1;

            URL url = new URL(urlString); 
            URLConnection conn = url.openConnection();

            if (!(conn instanceof HttpURLConnection))                     
                throw new IOException("Not an HTTP connection");

            try{
                HttpURLConnection httpConn = (HttpURLConnection) conn;
                httpConn.setAllowUserInteraction(false);
                httpConn.setInstanceFollowRedirects(true);
                httpConn.setRequestMethod("GET");
                httpConn.connect(); 

                response = httpConn.getResponseCode();                 
                if (response == HttpURLConnection.HTTP_OK) {
                    in = httpConn.getInputStream();                                 
                }                     
            }
            catch (Exception ex)
            {
                throw new IOException("Error connecting");            
            }
            return in;     
        }

private Bitmap DownloadImage(String URL)
{        
    Bitmap bitmap = null;
    InputStream in = null;        
    try {
        in = OpenHttpConnection(URL);
        bitmap = BitmapFactory.decodeStream(in);
        in.close();
    } catch (IOException e1) {
        // TODO Auto-generated catch block
        e1.printStackTrace();
    }
    return bitmap;                
}

并显示它

//Getting icon
            String iconURL = hmPlace.get("iconURL");
            Bitmap bitmap = DownloadImage(iconURL);
markerOptions.title(name + " : " + bitmap );
4

1 回答 1

0

MarkerOptions .title 将字符串作为参数,因此您不能将位图文件附加到它。

查看本教程以将标记添加到地图。要显示图像,您需要使用自定义 InfoWindowAdapter 设置自定义InfoWindow

于 2013-08-02T16:26:33.440 回答