动态显示信息窗口到GoogleMap的V2 [英] Show dynamically to InfoWindow Googlemap V2
问题描述
我正在开发一个旅游应用程序。在谷歌地图API V2的功能,我想每一个信息窗口有一个不同的图像。
I'm developing a travel app. On Google map API V2 feature, I want each InfoWindow have an different image.
我已经覆盖WindowInfoAdapter为自定义标题和细节文本。
I've override WindowInfoAdapter for custom title and detail text.
public class MyInfoWindowAdapter implements InfoWindowAdapter {
private final View mView;
public MyInfoWindowAdapter(Activity activity) {
mView = activity.getLayoutInflater().inflate(R.layout.custom_info_window, null);
}
@Override
public View getInfoContents(Marker marker){
String title = marker.getTitle();
final String snippet = marker.getSnippet();
final TextView titleUi = (TextView) mView.findViewById(R.id.title);
// final View subtitleUi = mView.findViewById(R.id.subtitle);
final TextView snippetUi = ((TextView) mView.findViewById(R.id.snippet));
final TextView placeid = ((TextView) mView.findViewById(R.id.placeid));
final RatingBar voteUi = ((RatingBar) mView.findViewById(R.id.ratingBar1));
final ImageView imageUi = ((ImageView) mView.findViewById(R.id.imageView1));
titleUi.setText(title);
//other code
return mView;
}
@Override
public View getInfoWindow(Marker marker){
return null;
}
}
这正常工作,因为它是字符串。结果
现在我想使用的ImageView的InforWindow添加图像。结果
出现问题,因为我使用的图像来自断言和数据流。这件事情是这样
It work fine because It's String.
Now I want to add an image on that InforWindow using ImageView.
The problem appear because I used image from asserts and stream. It's something like this
InputStream ims = getSherlockActivity().getAssets().open("images/" + imageSubPath + "/" + splitedImages[i].toLowerCase());
Drawable iImages = Drawable.createFromStream(ims, null);
我不能把可绘制对象片段,因为我之前做过的字符串。
我想在这里的结果:
I can't put Drawable object to snippet as I did with String before. The result I want here:
我怎样才能在信息窗口显示图像,任何意见都很大!
How can I display images on InfoWindows, any advices are great!
推荐答案
您需要创建额外的数据结构来保存您的图像,例如:
You would have to create additional data structure to hold your images, e.g.:
Map<Marker, Drawable> allMarkersMap = new HashMap<Marker, Drawable>();
在您添加标记的GoogleMap
:
allMarkersMap.put(marker, iImages);
在 getInfoContents
:
Drawable iImages = allMarkersMap.get(marker);
和它添加到的ImageView
。
另一种方法是使用 Android地图扩展,其中有像方法Marker.setData(对象)
和对象Marker.getData()
。这个你可以用它来直接分配可绘制
来标记,就像你做的片段。
Another way would be to use Android Maps Extensions, which has methods like Marker.setData(Object)
and Object Marker.getData()
. This you can use to directly assign Drawable
to marker, just like you do with snippet.
这篇关于动态显示信息窗口到GoogleMap的V2的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!