【发布时间】:2017-08-10 15:52:36
【问题描述】:
我在导航抽屉的片段中有一张地图。现在可以在导航抽屉的 MainActivity.java 中找到地图的代码。我在 onMapReady 中有一个 for 循环,它在我的地图上固定标记。现在 for 循环的每次迭代都从 Firebase 检索数据,以便能够固定标记。检索到的数据还包含图像的 URL,我需要使用这些 URL 在每个标记的信息窗口中显示图像。我试图了解提供的其他解决方案,但我不知道如何实现这一点。
这是我的代码到目前为止我的代码:
@Override
public void onMapReady(GoogleMap googleMap) {
mMap = googleMap;
...
for (infoToStore details : info) {
marker = mMap.addMarker(new MarkerOptions()
.position(new LatLng(Double.parseDouble(details.getLat()), Double.parseDouble(details.getLng())))
.title(details.getName())
.snippet(details.getDesc()));
}
}
编辑
我尝试如下实现它,但信息窗口是空白的;不显示 TextViews 和 ImageView。
@Override
public void onMapReady(GoogleMap googleMap) {
mMap = googleMap;
for (final infoToStore details : info) {
marker = mMap.addMarker(new MarkerOptions()
.position(new LatLng(Double.parseDouble(details.getLat()), Double.parseDouble(details.getLng())))
.title(details.getName())
.snippet(details.getDesc()));
mMap.setInfoWindowAdapter(new GoogleMap.InfoWindowAdapter() {
@Override
public View getInfoWindow(Marker marker) {
return null;
}
@Override
public View getInfoContents(Marker marker) {
View v = getLayoutInflater().inflate(R.layout.popup, null);
TextView name = (TextView) v.findViewById(R.id.name);
TextView desc = (TextView) v.findViewById(R.id.desc);
ImageView image = (ImageView) v.findViewById(R.id.image);
name.setText(marker.getTitle());
desc.setText(marker.getSnippet());
Picasso.with(getApplicationContext())
.load(URLString)
.into(image);
return v;
}
});
}
}
这是 popup.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/image"/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/name"/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/desc"/>
</LinearLayout>
【问题讨论】:
标签: android google-maps-markers google-maps-android-api-2