我正在尝试制作一个Android应用程序来向用户显示附近的餐馆。 我有一个谷歌地图显示,并添加标记与餐厅。当用户点击标记时,它会显示信息。餐厅,评级和图标的标题(如果存在)。 我正在使用Place search,我将获得每家餐厅的信息。 它的工作,但当我试图显示图标时,它显示为null。
听到的是我试图获得饱和度的图像的代码
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 );
答案 0 :(得分:0)
MarkerOptions .title以字符串作为参数,因此您无法将Bitmap文件附加到其中。
查看this tutorial,将标记添加到地图中。要显示图片,您需要使用自定义InfoWindowAdapter设置自定义InfoWindow。