【发布时间】:2017-11-12 21:23:20
【问题描述】:
我正在开发一个 Android 应用程序。 我需要将地图标记图标传递给它的信息窗口。
这是addMarker方法:
private void addMarker(LatLng latlng, final String title, final String nombre_apellidos, final String datosreporte,final String tiporeporte) {
markerOptions.position(latlng);
markerOptions.title(title);
markerOptions.snippet(nombre_apellidos+": "+datosreporte);
if (tiporeporte.equals("1")){
markerOptions.icon(BitmapDescriptorFactory.fromResource(R.drawable.tipo_1));
}
else{
markerOptions.icon(BitmapDescriptorFactory.fromResource(R.drawable.ic_actihome));
}
mGoogleMap.addMarker(markerOptions).showInfoWindow();
mGoogleMap.setOnInfoWindowClickListener(new GoogleMap.OnInfoWindowClickListener() {
@Override
public void onInfoWindowClick(Marker marker) {
Toast.makeText(getContext(), marker.getTitle(), Toast.LENGTH_SHORT).show();
}
});
}
这就是我创建信息窗口的方式:
public View getInfoWindow(Marker arg0) {
return null;
}
// Defines the contents of the InfoWindow
@Override
public View getInfoContents(Marker arg0) {
View v = null;
try {
// Getting view from the layout file info_window_layout
v = getLayoutInflater().inflate(R.layout.custominfowindow, null);
// Getting reference to the TextView to set latitude
TextView addressTxt = (TextView) v.findViewById(R.id.addressTxt);
TextView nameTxt = (TextView) v.findViewById(R.id.nameTxt);
ImageView icono = (ImageView) v.findViewById(R.id.iconoimagen);
addressTxt.setText(arg0.getTitle());
nameTxt.setText(arg0.getSnippet());
} catch (Exception ev) {
System.out.print(ev.getMessage());
}
return v;
}
我需要将标记图标放在 ImageView 图标中。
谢谢。
【问题讨论】:
-
不是最好的解决方案,但你可以试试这个链接stackoverflow.com/a/23237766/1548824
-
另一种解决方案是您可以使用
markeroption.setTag(yourvalue)并在 getInfoWindowagr0.getTag();中获取值,这将转换您自定义信息窗口中的值 -
@akhilesh0707, 选项 setTag 不适用于 markeroption....
-
@mvasco 如果您想获得图标,您有两个选择。首先将您的标记保存在哈希映射或其他东西中,然后从那里获取第二个是使用 markeroption.getIcon() 来获取图标。但我认为 getIcon 方法仅在谷歌地图的 web api 中可用。
标签: android google-maps